home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / as.sun3 / m68k.c < prev    next >
C/C++ Source or Header  |  1990-02-16  |  77KB  |  3,370 lines

  1. /* m68k.c  All the m68020 specific stuff in one convenient, huge,
  2.    slow to compile, easy to find file.
  3.    Copyright (C) 1987 Free Software Foundation, Inc.
  4.  
  5. This file is part of GAS, the GNU Assembler.
  6.  
  7. GAS is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 1, or (at your option)
  10. any later version.
  11.  
  12. GAS is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with GAS; see the file COPYING.  If not, write to
  19. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. #include <stdio.h>
  22. #include <ctype.h>
  23.  
  24. #include "m68k-opcode.h"
  25. #include "as.h"
  26. #include "obstack.h"
  27. #include "frags.h"
  28. #include "struc-symbol.h"
  29. #include "flonum.h"
  30. #include "expr.h"
  31. #include "hash.h"
  32. #include "md.h"
  33. #include "m68k.h"
  34.  
  35. #ifdef M_SUN
  36. /* This variable contains the value to write out at the beginning of
  37.    the a.out file.  The 2<<16 means that this is a 68020 file instead
  38.    of an old-style 68000 file */
  39.  
  40. long omagic = 2<<16|OMAGIC;    /* Magic byte for header file */
  41. #else
  42. long omagic = OMAGIC;
  43. #endif
  44.  
  45.  
  46. /* This array holds the chars that always start a comment.  If the
  47.    pre-processor is disabled, these aren't very useful */
  48. char comment_chars[] = "|";
  49.  
  50. /* This array holds the chars that only start a comment at the beginning of
  51.    a line.  If the line seems to have the form '# 123 filename'
  52.    .line and .file directives will appear in the pre-processed output */
  53. /* Note that input_file.c hand checks for '#' at the beginning of the
  54.    first line of the input file.  This is because the compiler outputs
  55.    #NO_APP at the beginning of its output. */
  56. /* Also note that '/*' will always start a comment */
  57. char line_comment_chars[] = "#";
  58.  
  59. /* Chars that can be used to separate mant from exp in floating point nums */
  60. char EXP_CHARS[] = "eE";
  61.  
  62. /* Chars that mean this number is a floating point constant */
  63. /* As in 0f12.456 */
  64. /* or    0d1.2345e12 */
  65.  
  66. char FLT_CHARS[] = "rRsSfFdDxXeEpP";
  67.  
  68. /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
  69.    changed in read.c .  Ideally it shouldn't have to know about it at all,
  70.    but nothing is ideal around here.
  71.  */
  72.  
  73. void fix_new();
  74. void install_operand();
  75. void install_gen_operand();
  76.  
  77. /* Its an arbitrary name:  This means I don't approve of it */
  78. /* See flames below */
  79. struct obstack robyn;
  80.  
  81. #define TAB(x,y)    (((x)<<2)+(y))
  82. #define TABTYPE(xy)     ((xy) >> 2)
  83. #define BYTE        0
  84. #define SHORT        1
  85. #define LONG        2
  86. #define SZ_UNDEF    3
  87.  
  88. #define BRANCH        1
  89. #define FBRANCH        2
  90. #define PCREL        3
  91. #define BCC68000        4
  92. #define DBCC            5
  93.  
  94. /* BCC68000 is for patching in an extra jmp instruction for long offsets
  95.    on the 68000.  The 68000 doesn't support long branches with branchs */
  96.  
  97. /* This table desribes how you change sizes for the various types of variable
  98.    size expressions.  This version only supports two kinds. */
  99.  
  100. /* Note that calls to frag_var need to specify the maximum expansion needed */
  101. /* This is currently 10 bytes for DBCC */
  102.  
  103. /* The fields are:
  104.     How far Forward this mode will reach:
  105.     How far Backward this mode will reach:
  106.     How many bytes this mode will add to the size of the frag
  107.     Which mode to go to if the offset won't fit in this one
  108.  */
  109. relax_typeS
  110. md_relax_table[] = {
  111. { 1,        1,        0,    0 },    /* First entries aren't used */
  112. { 1,        1,        0,    0 },    /* For no good reason except */
  113. { 1,        1,        0,    0 },    /* that the VAX doesn't either */
  114. { 1,        1,        0,    0 },
  115.  
  116. { (127),    (-128),        0,    TAB(BRANCH,SHORT)},
  117. { (2+32767),    (2+-32768),    2,    TAB(BRANCH,LONG) },
  118. { 0,        0,        4,    0 },
  119. { 1,        1,        0,    0 },
  120.  
  121. { 1,        1,        0,    0 },    /* FBRANCH doesn't come BYTE */
  122. { (2+32767),    (2+-32768),    2,    TAB(FBRANCH,LONG)},
  123. { 0,        0,        4,    0 },
  124. { 1,        1,        0,    0 },
  125.  
  126. { 1,        1,        0,    0 },    /* PCREL doesn't come BYTE */
  127. { (2+32767),    (2+-32768),    2,    TAB(PCREL,LONG)},
  128. { 0,        0,        4,    0 },
  129. { 1,        1,        0,    0 },
  130.  
  131. { (127),        (-128),         0,      TAB(BCC68000,SHORT)},
  132. { (2+32767),    (2+-32768),     2,      TAB(BCC68000,LONG) },
  133. { 0,            0,              6,      0 },  /* jmp long space */
  134. { 1,            1,              0,      0 },
  135.  
  136. { 1,            1,              0,      0 },  /* DBCC doesn't come BYTE */
  137. { (2+32767),    (2+-32768),     2,      TAB(DBCC,LONG) },
  138. { 0,            0,             10,      0 },  /* bra/jmp long space */
  139. { 1,            1,              0,      0 },
  140.  
  141. };
  142.  
  143. void    s_data1(),    s_data2(),    s_even(),    s_space();
  144. void    float_cons();
  145.  
  146. /* These are the machine dependent pseudo-ops.  These are included so
  147.    the assembler can work on the output from the SUN C compiler, which
  148.    generates these.
  149.  */
  150.  
  151. /* This table describes all the machine specific pseudo-ops the assembler
  152.    has to support.  The fields are:
  153.          pseudo-op name without dot
  154.       function to call to execute this pseudo-op
  155.       Integer arg to pass to the function
  156.  */
  157. pseudo_typeS md_pseudo_table[] = {
  158.     { "data1",    s_data1,    0    },
  159.     { "data2",    s_data2,    0    },
  160.     { "even",    s_even,        0    },
  161.     { "skip",    s_space,    0    },
  162.     { 0,        0,        0    }
  163. };
  164.  
  165.  
  166. /* #define isbyte(x)    ((x)>=-128 && (x)<=127) */
  167. /* #define isword(x)    ((x)>=-32768 && (x)<=32767) */
  168.  
  169. #define issbyte(x)    ((x)>=-128 && (x)<=127)
  170. #define isubyte(x)    ((x)>=0 && (x)<=255)
  171. #define issword(x)    ((x)>=-32768 && (x)<=32767)
  172. #define isuword(x)    ((x)>=0 && (x)<=65535)
  173.  
  174. #define isbyte(x)    ((x)>=-128 && (x)<=255)
  175. #define isword(x)    ((x)>=-32768 && (x)<=65535)
  176. #define islong(x)    (1)
  177.  
  178. char *input_line_pointer;
  179.  
  180. /* Operands we can parse:  (And associated modes)
  181.  
  182. numb:    8 bit num
  183. numw:    16 bit num
  184. numl:    32 bit num
  185. dreg:    data reg 0-7
  186. reg:    address or data register
  187. areg:    address register
  188. apc:    address register, PC, ZPC or empty string
  189. num:    16 or 32 bit num
  190. num2:    like num
  191. sz:    w or l        if omitted, l assumed
  192. scale:    1 2 4 or 8    if omitted, 1 assumed
  193.  
  194. 7.4 IMMED #num                --> NUM
  195. 0.? DREG  dreg                --> dreg
  196. 1.? AREG  areg                --> areg
  197. 2.? AINDR areg@                --> *(areg)
  198. 3.? AINC  areg@+            --> *(areg++)
  199. 4.? ADEC  areg@-            --> *(--areg)
  200. 5.? AOFF  apc@(numw)            --> *(apc+numw)    -- empty string and ZPC not allowed here
  201. 6.? AINDX apc@(num,reg:sz:scale)    --> *(apc+num+reg*scale)
  202. 6.? AINDX apc@(reg:sz:scale)        --> same, with num=0
  203. 6.? APODX apc@(num)@(num2,reg:sz:scale)    --> *(*(apc+num)+num2+reg*scale)
  204. 6.? APODX apc@(num)@(reg:sz:scale)    --> same, with num2=0
  205. 6.? AMIND apc@(num)@(num2)        --> *(*(apc+num)+num2) (previous mode without an index reg)
  206. 6.? APRDX apc@(num,reg:sz:scale)@(num2)    --> *(*(apc+num+reg*scale)+num2)
  207. 6.? APRDX apc@(reg:sz:scale)@(num2)    --> same, with num=0
  208. 7.0 ABSL  num:sz            --> *(num)
  209.           num                --> *(num) (sz L assumed)
  210. *** MSCR  otherreg            --> Magic
  211. With -l option
  212. 5.? AOFF  apc@(num)            --> *(apc+num) -- empty string and ZPC not allowed here still
  213.  
  214. examples:
  215.     #foo    #0x35    #12
  216.     d2
  217.     a4
  218.     a3@
  219.     a5@+
  220.     a6@-
  221.     a2@(12)    pc@(14)
  222.     a1@(5,d2:w:1)    @(45,d6:l:4)
  223.     pc@(a2)        @(d4)
  224.     etc . . .
  225.  
  226.  
  227. #name@(numw)    -->turn into PC rel mode
  228. apc@(num8,reg:sz:scale)        --> *(apc+num8+reg*scale)
  229.  
  230. */
  231.  
  232. #define IMMED    1
  233. #define DREG    2
  234. #define AREG    3
  235. #define AINDR    4
  236. #define ADEC    5
  237. #define AINC    6
  238. #define AOFF    7
  239. #define AINDX    8
  240. #define APODX    9
  241. #define AMIND    10
  242. #define APRDX    11
  243. #define ABSL    12
  244. #define MSCR    13
  245. #define REGLST    14
  246.  
  247. #define FAIL    0
  248. #define OK    1
  249.  
  250. /* DATA and ADDR have to be contiguous, so that reg-DATA gives 0-7==data reg,
  251.    8-15==addr reg for operands that take both types */
  252. #define DATA    1        /*   1- 8 == data registers 0-7 */
  253. #define ADDR    (DATA+8)    /*   9-16 == address regs 0-7 */
  254. #define FPREG    (ADDR+8)    /*  17-24 Eight FP registers */
  255. #define COPNUM    (FPREG+8)    /*  25-32 Co-processor #1-#8 */
  256.  
  257. #define PC    (COPNUM+8)    /*  33 Program counter */
  258. #define ZPC    (PC+1)        /*  34 Hack for Program space, but 0 addressing */
  259. #define SR    (ZPC+1)        /*  35 Status Reg */
  260. #define CCR    (SR+1)        /*  36 Condition code Reg */
  261.  
  262. /* These have to be in order for the movec instruction to work. */
  263. #define USP    (CCR+1)        /*  37 User Stack Pointer */
  264. #define ISP    (USP+1)        /*  38 Interrupt stack pointer */
  265. #define SFC    (ISP+1)        /*  39 */
  266. #define DFC    (SFC+1)        /*  40 */
  267. #define CACR    (DFC+1)        /*  41 */
  268. #define VBR    (CACR+1)    /*  42 */
  269. #define CAAR    (VBR+1)        /*  43 */
  270. #define MSP    (CAAR+1)    /*  44 */
  271.  
  272. #define FPI    (MSP+1)        /* 45 */
  273. #define FPS    (FPI+1)        /* 46 */
  274. #define FPC    (FPS+1)        /* 47 */
  275. /*
  276.  * these defines should be in m68k.c but
  277.  * i put them here to keep all the m68851 stuff
  278.  * together -rab
  279.  * JF--Make sure these #s don't clash with the ones in m68k.c
  280.  * That would be BAD.
  281.  */
  282. #define TC    (FPC+1)        /* 48 */
  283. #define DRP    (TC+1)        /* 49 */
  284. #define SRP    (DRP+1)        /* 50 */
  285. #define CRP    (SRP+1)        /* 51 */
  286. #define CAL    (CRP+1)        /* 52 */
  287. #define VAL    (CAL+1)        /* 53 */
  288. #define SCC    (VAL+1)        /* 54 */
  289. #define AC    (SCC+1)        /* 55 */
  290. #define BAD    (AC+1)        /* 56,57,58,59, 60,61,62,63 */
  291. #define BAC    (BAD+8)        /* 64,65,66,67, 68,69,70,71 */
  292. #define PSR    (BAC+8)        /* 72 */
  293. #define PCSR    (PSR+1)        /* 73 */
  294.  
  295.  
  296. /* Note that COPNUM==processor #1 -- COPNUM+7==#8, which stores as 000 */
  297. /* I think. . .  */
  298.  
  299. #define    SP    ADDR+7
  300.  
  301. /* JF these tables here are for speed at the expense of size */
  302. /* You can replace them with the #if 0 versions if you really
  303.    need space and don't mind it running a bit slower */
  304.  
  305. static char mklower_table[256];
  306. #define mklower(c) (mklower_table[(unsigned char)(c)])
  307. static char notend_table[256];
  308. static char alt_notend_table[256];
  309. #define notend(s) ( !(notend_table[(unsigned char)(*s)] || (*s==':' &&\
  310.  alt_notend_table[(unsigned char)(s[1])])))
  311.  
  312. #if 0
  313. #define mklower(c)    (isupper(c) ? tolower(c) : c)
  314. #endif
  315.  
  316.  
  317. struct m68k_exp {
  318.     char    *e_beg;
  319.     char    *e_end;
  320.     expressionS e_exp;
  321.     short    e_siz;        /* 0== default 1==short/byte 2==word 3==long */
  322. };
  323.  
  324. /* Internal form of an operand.  */
  325. struct m68k_op {
  326.     char    *error;        /* Couldn't parse it */
  327.     int    mode;        /* What mode this instruction is in.  */
  328.     unsigned long int    reg;        /* Base register */
  329.     struct m68k_exp *con1;
  330.     int    ireg;        /* Index register */
  331.     int    isiz;        /* 0==unspec  1==byte(?)  2==short  3==long  */
  332.     int    imul;        /* Multipy ireg by this (1,2,4,or 8) */
  333.     struct    m68k_exp *con2;
  334. };
  335.  
  336. /* internal form of a 68020 instruction */
  337. struct m68_it {
  338.     char    *error;
  339.     char    *args;        /* list of opcode info */
  340.     int    numargs;
  341.  
  342.     int    numo;        /* Number of shorts in opcode */
  343.     short    opcode[11];
  344.  
  345.     struct m68k_op operands[6];
  346.  
  347.     int    nexp;        /* number of exprs in use */
  348.     struct m68k_exp exprs[4];
  349.  
  350.     int    nfrag;        /* Number of frags we have to produce */
  351.     struct {
  352.         int fragoff;    /* Where in the current opcode[] the frag ends */
  353.         symbolS *fadd;
  354.         long int foff;
  355.         int fragty;
  356.     } fragb[4];
  357.  
  358.     int    nrel;        /* Num of reloc strucs in use */
  359.     struct    {
  360.         int    n;
  361.         symbolS    *add,
  362.             *sub;
  363.         long int off;
  364.         char    wid;
  365.         char    pcrel;
  366.     } reloc[5];        /* Five is enough??? */
  367. };
  368.  
  369. struct m68_it the_ins;        /* the instruction being assembled */
  370.  
  371.  
  372. /* Macros for adding things to the m68_it struct */
  373.  
  374. #define addword(w)    the_ins.opcode[the_ins.numo++]=(w)
  375.  
  376. /* Like addword, but goes BEFORE general operands */
  377. #define insop(w)    {int z;\
  378.  for(z=the_ins.numo;z>opcode->m_codenum;--z)\
  379.    the_ins.opcode[z]=the_ins.opcode[z-1];\
  380.  for(z=0;z<the_ins.nrel;z++)\
  381.    the_ins.reloc[z].n+=2;\
  382.  the_ins.opcode[opcode->m_codenum]=w;\
  383.  the_ins.numo++;\
  384. }
  385.  
  386.  
  387. #define add_exp(beg,end) (\
  388.     the_ins.exprs[the_ins.nexp].e_beg=beg,\
  389.     the_ins.exprs[the_ins.nexp].e_end=end,\
  390.     &the_ins.exprs[the_ins.nexp++]\
  391. )
  392.  
  393.  
  394. /* The numo+1 kludge is so we can hit the low order byte of the prev word. Blecch*/
  395. #define add_fix(width,exp,pc_rel) {\
  396.     the_ins.reloc[the_ins.nrel].n= ((width)=='B') ? (the_ins.numo*2-1) : \
  397.         (((width)=='b') ? ((the_ins.numo-1)*2) : (the_ins.numo*2));\
  398.     the_ins.reloc[the_ins.nrel].add=adds((exp));\
  399.     the_ins.reloc[the_ins.nrel].sub=subs((exp));\
  400.     the_ins.reloc[the_ins.nrel].off=offs((exp));\
  401.     the_ins.reloc[the_ins.nrel].wid=width;\
  402.     the_ins.reloc[the_ins.nrel++].pcrel=pc_rel;\
  403. }
  404.  
  405. #define add_frag(add,off,type)  {\
  406.     the_ins.fragb[the_ins.nfrag].fragoff=the_ins.numo;\
  407.     the_ins.fragb[the_ins.nfrag].fadd=add;\
  408.     the_ins.fragb[the_ins.nfrag].foff=off;\
  409.     the_ins.fragb[the_ins.nfrag++].fragty=type;\
  410. }
  411.  
  412. #define isvar(exp)    ((exp) && (adds(exp) || subs(exp)))
  413.  
  414. #define seg(exp)    ((exp)->e_exp.X_seg)
  415. #define adds(exp)    ((exp)->e_exp.X_add_symbol)
  416. #define subs(exp)    ((exp)->e_exp.X_subtract_symbol)
  417. #define offs(exp)    ((exp)->e_exp.X_add_number)
  418.  
  419.  
  420. struct m68_incant {
  421.     char *m_operands;
  422.     unsigned long m_opcode;
  423.     short m_opnum;
  424.     short m_codenum;
  425.     struct m68_incant *m_next;
  426. };
  427.  
  428. #define getone(x)    ((((x)->m_opcode)>>16)&0xffff)
  429. #define gettwo(x)    (((x)->m_opcode)&0xffff)
  430.  
  431.  
  432. /* JF modified this to handle cases where the first part of a symbol name
  433.    looks like a register */
  434.  
  435. int
  436. m68k_reg_parse(ccp)
  437. register char **ccp;
  438. {
  439.     register char c1,
  440.         c2,
  441.         c3,
  442.         c4;
  443.     register int n = 0,
  444.         ret;
  445.  
  446.     c1=mklower(ccp[0][0]);
  447.     c2=mklower(ccp[0][1]);
  448.     c3=mklower(ccp[0][2]);
  449.     c4=mklower(ccp[0][3]);
  450.  
  451.     switch(c1) {
  452.     case 'a':
  453.         if(c2>='0' && c2<='7') {
  454.             n=2;
  455.             ret=ADDR+c2-'0';
  456.         }
  457. #ifdef m68851
  458.         else if (c2 == 'c') {
  459.             n = 2;
  460.             ret = AC;
  461.         }
  462. #endif
  463.         break;
  464. #ifdef m68851
  465.     case 'b':
  466.         if (c2 == 'a') {
  467.             if (c3 == 'd') {
  468.                 if (c4 >= '0' && c4 <= '7') {
  469.                     n = 4;
  470.                     ret = BAD + c4 - '0';
  471.                 }
  472.             }
  473.             if (c3 == 'c') {
  474.                 if (c4 >= '0' && c4 <= '7') {
  475.                     n = 4;
  476.                     ret = BAC + c4 - '0';
  477.                 }
  478.             }
  479.         }
  480.         break;
  481. #endif
  482.     case 'c':
  483. #ifdef m68851
  484.         if (c2 == 'a' && c3 == 'l') {
  485.             n = 3;
  486.             ret = CAL;
  487.         } else
  488. #endif
  489.             /* This supports both CCR and CC as the ccr reg. */
  490.         if(c2=='c' && c3=='r') {
  491.             n=3;
  492.             ret = CCR;
  493.         } else if(c2=='c') {
  494.             n=2;
  495.             ret = CCR;
  496.         } else if(c2=='a' && (c3=='a' || c3=='c') && c4=='r') {
  497.             n=4;
  498.             ret = c3=='a' ? CAAR : CACR;
  499.         }
  500. #ifdef m68851
  501.         else if (c2 == 'r' && c3 == 'p') {
  502.             n = 3;
  503.             ret = (CRP);
  504.         }
  505. #endif
  506.         break;
  507.     case 'd':
  508.         if(c2>='0' && c2<='7') {
  509.             n=2;
  510.             ret = DATA+c2-'0';
  511.         } else if(c2=='f' && c3=='c') {
  512.             n=3;
  513.             ret = DFC;
  514.         }
  515. #ifdef m68851
  516.         else if (c2 == 'r' && c3 == 'p') {
  517.             n = 3;
  518.             ret = (DRP);
  519.         }
  520. #endif
  521.         break;
  522.     case 'f':
  523.         if(c2=='p') {
  524.              if(c3>='0' && c3<='7') {
  525.                 n=3;
  526.                 ret = FPREG+c3-'0';
  527.             } else if(c3=='i') {
  528.                 n=3;
  529.                 ret = FPI;
  530.             } else if(c3=='s') {
  531.                 n= (c4 == 'r' ? 4 : 3);
  532.                 ret = FPS;
  533.             } else if(c3=='c') {
  534.                 n= (c4 == 'r' ? 4 : 3);
  535.                 ret = FPC;
  536.             }
  537.         }
  538.         break;
  539.     case 'i':
  540.         if(c2=='s' && c3=='p') {
  541.             n=3;
  542.             ret = ISP;
  543.         }
  544.         break;
  545.     case 'm':
  546.         if(c2=='s' && c3=='p') {
  547.             n=3;
  548.             ret = MSP;
  549.         }
  550.         break;
  551.     case 'p':
  552.         if(c2=='c') {
  553. #ifdef m68851
  554.             if(c3 == 's' && c4=='r') {
  555.                 n=4;
  556.                 ret = (PCSR);
  557.             } else
  558. #endif
  559.             {
  560.                 n=2;
  561.                 ret = PC;
  562.             }
  563.         }
  564. #ifdef m68851
  565.         else if (c2 == 's' && c3 == 'r') {
  566.             n = 3;
  567.             ret = (PSR);
  568.         }
  569. #endif
  570.         break;
  571.     case 's':
  572. #ifdef m68851
  573.         if (c2 == 'c' && c3 == 'c') {
  574.             n = 3;
  575.             ret = (SCC);
  576.         } else if (c2 == 'r' && c3 == 'p') {
  577.             n = 3;
  578.             ret = (SRP);
  579.         } else
  580. #endif
  581.         if(c2=='r') {
  582.             n=2;
  583.             ret = SR;
  584.         } else if(c2=='p') {
  585.             n=2;
  586.             ret = ADDR+7;
  587.         } else if(c2=='f' && c3=='c') {
  588.             n=3;
  589.             ret = SFC;
  590.         }
  591.         break;
  592. #ifdef m68851
  593.     case 't':
  594.         if(c2 == 'c') {
  595.             n=2;
  596.             ret=TC;
  597.         }
  598.         break;
  599. #endif
  600.     case 'u':
  601.         if(c2=='s' && c3=='p') {
  602.             n=3;
  603.             ret = USP;
  604.         }
  605.         break;
  606.     case 'v':
  607. #ifdef m68851
  608.         if (c2 == 'a' && c3 == 'l') {
  609.             n = 3;
  610.             ret = (VAL);
  611.         } else
  612. #endif
  613.         if(c2=='b' && c3=='r') {
  614.             n=3;
  615.             ret = VBR;
  616.         }
  617.         break;
  618.     case 'z':
  619.         if(c2=='p' && c3=='c') {
  620.             n=3;
  621.             ret = ZPC;
  622.         }
  623.         break;
  624.     default:
  625.         break;
  626.     }
  627.     if(n) {
  628.         if(isalnum(ccp[0][n]) || ccp[0][n]=='_')
  629.             ret=FAIL;
  630.         else
  631.             ccp[0]+=n;
  632.     } else
  633.         ret = FAIL;
  634.     return ret;
  635. }
  636.  
  637. #define SKIP_WHITE()    { str++; if(*str==' ') str++;}
  638.  
  639. int
  640. m68k_ip_op(str,opP)
  641. char *str;
  642. register struct m68k_op *opP;
  643. {
  644.     char    *strend;
  645.     long    i;
  646.     char    *parse_index();
  647.  
  648.     if(*str==' ')
  649.         str++;
  650.         /* Find the end of the string */
  651.     if(!*str) {
  652.         /* Out of gas */
  653.         opP->error="Missing operand";
  654.         return FAIL;
  655.     }
  656.     for(strend=str;*strend;strend++)
  657.         ;
  658.     --strend;
  659.  
  660.         /* Guess what:  A constant.  Shar and enjoy */
  661.     if(*str=='#') {
  662.         str++;
  663.         opP->con1=add_exp(str,strend);
  664.         opP->mode=IMMED;
  665.         return OK;
  666.     }
  667.     i=m68k_reg_parse(&str);
  668.     if((i==FAIL || *str!='\0') && *str!='@') {
  669.         char *stmp;
  670.         char *index();
  671.  
  672.         if(i!=FAIL && (*str=='/' || *str=='-')) {
  673.             opP->mode=REGLST;
  674.             return get_regs(i,str,opP);
  675.         }
  676.         if(stmp=index(str,'@')) {
  677.             opP->con1=add_exp(str,stmp-1);
  678.             if(stmp==strend) {
  679.                 opP->mode=AINDX;
  680.                 return OK;
  681.             }
  682.             stmp++;
  683.             if(*stmp++!='(' || *strend--!=')') {
  684.                 opP->error="Malformed operand";
  685.                 return FAIL;
  686.             }
  687.             i=try_index(&stmp,opP);
  688.             opP->con2=add_exp(stmp,strend);
  689.             if(i==FAIL) opP->mode=AMIND;
  690.             else opP->mode=APODX;
  691.             return OK;
  692.         }
  693.         opP->mode=ABSL;
  694.         if(strend[-1]==':') {    /* mode ==foo:[wl] */
  695.             switch(*strend) {
  696.             case 'w':
  697.             case 'W':
  698.                 opP->isiz=2;
  699.                 break;
  700.             case 'l':
  701.             case 'L':
  702.                 opP->isiz=3;
  703.                 break;
  704.             default:
  705.                 opP->error="size spec not :w or :l";
  706.                 return FAIL;
  707.             }
  708.             strend-=2;
  709.         } else {
  710.             opP->isiz=0;
  711.         }
  712.  
  713.         opP->con1=add_exp(str,strend);
  714.         return OK;
  715.     }
  716.     opP->reg=i;
  717.     if(*str=='\0') {
  718.         if(i>=DATA+0 && i<=DATA+7)
  719.             opP->mode=DREG;
  720.         else if(i>=ADDR+0 && i<=ADDR+7)
  721.             opP->mode=AREG;
  722.         else
  723.             opP->mode=MSCR;
  724.         return OK;
  725.     }
  726.     if((i<ADDR+0 || i>ADDR+7) && i!=PC && i!=ZPC && i!=FAIL) {    /* Can't indirect off non address regs */
  727.         opP->error="Invalid indirect register";
  728.         return FAIL;
  729.     }
  730.     if(*str!='@')
  731.         abort();
  732.     str++;
  733.     switch(*str) {
  734.     case '\0':
  735.         opP->mode=AINDR;
  736.         return OK;
  737.     case '-':
  738.         opP->mode=ADEC;
  739.         return OK;
  740.     case '+':
  741.         opP->mode=AINC;
  742.         return OK;
  743.     case '(':
  744.         str++;
  745.         break;
  746.     default:
  747.         opP->error="Junk after indirect";
  748.         return FAIL;
  749.     }
  750.         /* Some kind of indexing involved.  Lets find out how bad it is */
  751.     i=try_index(&str,opP);
  752.         /* Didn't start with an index reg, maybe its offset or offset,reg */
  753.     if(i==FAIL) {
  754.         char *beg_str;
  755.  
  756.         beg_str=str;
  757.         for(i=1;i;) {
  758.             switch(*str++) {
  759.             case '\0':
  760.                 opP->error="Missing )";
  761.                 return FAIL;
  762.             case ',': i=0; break;
  763.             case '(': i++; break;
  764.             case ')': --i; break;
  765.             }
  766.         }
  767.         opP->con1=add_exp(beg_str,str-2);
  768.             /* Should be offset,reg */
  769.         if(str[-1]==',') {
  770.             i=try_index(&str,opP);
  771.             if(i==FAIL) {
  772.                 opP->error="Malformed index reg";
  773.                 return FAIL;
  774.             }
  775.         }
  776.     }
  777.         /* We've now got offset)   offset,reg)   or    reg) */
  778.  
  779.     if(*str=='\0') {
  780.         /* Th-the-thats all folks */
  781.         if(opP->reg==FAIL) opP->mode=AINDX;    /* Other form of indirect */
  782.         else if(opP->ireg==FAIL) opP->mode=AOFF;
  783.         else opP->mode=AINDX;
  784.         return OK;
  785.     }
  786.         /* Next thing had better be another @ */
  787.     if(*str!='@' || str[1]!='(') {
  788.         opP->error="junk after indirect";
  789.         return FAIL;
  790.     }
  791.     str+=2;
  792.     if(opP->ireg!=FAIL) {
  793.         opP->mode=APRDX;
  794.         i=try_index(&str,opP);
  795.         if(i!=FAIL) {
  796.             opP->error="Two index registers!  not allowed!";
  797.             return FAIL;
  798.         }
  799.     } else
  800.         i=try_index(&str,opP);
  801.     if(i==FAIL) {
  802.         char *beg_str;
  803.  
  804.         beg_str=str;
  805.         for(i=1;i;) {
  806.             switch(*str++) {
  807.             case '\0':
  808.                 opP->error="Missing )";
  809.                 return FAIL;
  810.             case ',': i=0; break;
  811.             case '(': i++; break;
  812.             case ')': --i; break;
  813.             }
  814.         }
  815.         opP->con2=add_exp(beg_str,str-2);
  816.         if(str[-1]==',') {
  817.             if(opP->ireg!=FAIL) {
  818.                 opP->error="Can't have two index regs";
  819.                 return FAIL;
  820.             }
  821.             i=try_index(&str,opP);
  822.             if(i==FAIL) {
  823.                 opP->error="malformed index reg";
  824.                 return FAIL;
  825.             }
  826.             opP->mode=APODX;
  827.         } else if(opP->ireg!=FAIL)
  828.             opP->mode=APRDX;
  829.         else
  830.             opP->mode=AMIND;
  831.     } else
  832.         opP->mode=APODX;
  833.     if(*str!='\0') {
  834.         opP->error="Junk after indirect";
  835.         return FAIL;
  836.     }
  837.     return OK;
  838. }
  839.  
  840. int
  841. try_index(s,opP)
  842. char **s;
  843. struct m68k_op *opP;
  844. {
  845.     register int    i;
  846.     char    *ss;
  847. #define SKIP_W()    { ss++; if(*ss==' ') ss++;}
  848.  
  849.     ss= *s;
  850.     /* SKIP_W(); */
  851.     i=m68k_reg_parse(&ss);
  852.     if(!(i>=DATA+0 && i<=ADDR+7)) {    /* if i is not DATA or ADDR reg */
  853.         *s=ss;
  854.         return FAIL;
  855.     }
  856.     opP->ireg=i;
  857.     /* SKIP_W(); */
  858.     if(*ss==')') {
  859.         opP->isiz=0;
  860.         opP->imul=1;
  861.         SKIP_W();
  862.         *s=ss;
  863.         return OK;
  864.     }
  865.     if(*ss!=':') {
  866.         opP->error="Missing : in index register";
  867.         *s=ss;
  868.         return FAIL;
  869.     }
  870.     SKIP_W();
  871.     if(mklower(*ss)=='w') opP->isiz=2;
  872.     else if(mklower(*ss)=='l') opP->isiz=3;
  873.     else {
  874.         opP->error="Size spec not :w or :l";
  875.         *s=ss;
  876.         return FAIL;
  877.     }
  878.     SKIP_W();
  879.     if(*ss==':') {
  880.         SKIP_W();
  881.         switch(*ss) {
  882.         case '1':
  883.         case '2':
  884.         case '4':
  885.         case '8':
  886.             opP->imul= *ss-'0';
  887.             break;
  888.         default:
  889.             opP->error="index multiplier not 1, 2, 4 or 8";
  890.             *s=ss;
  891.             return FAIL;
  892.         }
  893.         SKIP_W();
  894.     } else opP->imul=1;
  895.     if(*ss!=')') {
  896.         opP->error="Missing )";
  897.         *s=ss;
  898.         return FAIL;
  899.     }
  900.     SKIP_W();
  901.     *s=ss;
  902.     return OK;
  903. }
  904.  
  905. #ifdef TEST1    /* TEST1 tests m68k_ip_op(), which parses operands */
  906. main()
  907. {
  908.     char buf[128];
  909.     struct m68k_op thark;
  910.  
  911.     for(;;) {
  912.         if(!gets(buf))
  913.             break;
  914.         bzero(&thark,sizeof(thark));
  915.         if(!m68k_ip_op(buf,&thark)) printf("FAIL:");
  916.         if(thark.error)
  917.             printf("op1 error %s in %s\n",thark.error,buf);
  918.         printf("mode %d, reg %d, ",thark.mode,thark.reg);
  919.         if(thark.b_const)
  920.             printf("Constant: '%.*s',",1+thark.e_const-thark.b_const,thark.b_const);
  921.         printf("ireg %d, isiz %d, imul %d ",thark.ireg,thark.isiz,thark.imul);
  922.         if(thark.b_iadd)
  923.             printf("Iadd: '%.*s'",1+thark.e_iadd-thark.b_iadd,thark.b_iadd);
  924.         printf("\n");
  925.     }
  926.     exit(0);
  927. }
  928.  
  929. #endif
  930.  
  931.  
  932. static struct hash_control*   op_hash = NULL;    /* handle of the OPCODE hash table
  933.                    NULL means any use before m68_ip_begin()
  934.                    will crash */
  935.  
  936.  
  937. /*
  938.  *                  m 6 8 _ i p ( )
  939.  *
  940.  * This converts a string into a 68k instruction.
  941.  * The string must be a bare single instruction in sun format
  942.  * with RMS-style 68020 indirects
  943.  *  (example:  )
  944.  *
  945.  * It provides some error messages: at most one fatal error message (which
  946.  * stops the scan) and at most one warning message for each operand.
  947.  * The 68k instruction is returned in exploded form, since we have no
  948.  * knowledge of how you parse (or evaluate) your expressions.
  949.  * We do however strip off and decode addressing modes and operation
  950.  * mnemonic.
  951.  *
  952.  * This function's value is a string. If it is not "" then an internal
  953.  * logic error was found: read this code to assign meaning to the string.
  954.  * No argument string should generate such an error string:
  955.  * it means a bug in our code, not in the user's text.
  956.  *
  957.  * You MUST have called m86_ip_begin() once and m86_ip_end() never before using
  958.  * this function.
  959.  */
  960.  
  961. /* JF this function no longer returns a useful value.  Sorry */
  962. void
  963. m68_ip (instring)
  964. char    *instring;
  965. {
  966.     register char *p;
  967.     register struct m68k_op *opP;
  968.     register struct m68_incant *opcode;
  969.     register char *s;
  970.     register int tmpreg,
  971.         baseo,
  972.         outro,
  973.         nextword;
  974.     int    siz1,
  975.         siz2;
  976.     char    c;
  977.     int    losing;
  978.     int    opsfound;
  979.     char    *crack_operand();
  980.     char    *atof_m68k();
  981.     LITTLENUM_TYPE words[6];
  982.     LITTLENUM_TYPE *wordp;
  983.  
  984.     if (*instring == ' ')
  985.         instring++;            /* skip leading whitespace */
  986.  
  987.   /* Scan up to end of operation-code, which MUST end in end-of-string
  988.      or exactly 1 space. */
  989.     for (p = instring; *p != '\0'; p++)
  990.         if (*p == ' ')
  991.             break;
  992.  
  993.  
  994.     if (p == instring) {
  995.         the_ins.error = "No operator";
  996.         the_ins.opcode[0] = NULL;
  997.         /* the_ins.numo=1; */
  998.         return;
  999.     }
  1000.  
  1001.   /* p now points to the end of the opcode name, probably whitespace.
  1002.      make sure the name is null terminated by clobbering the whitespace,
  1003.      look it up in the hash table, then fix it back. */   
  1004.     c = *p;
  1005.     *p = '\0';
  1006.     opcode = (struct m68_incant *)hash_find (op_hash, instring);
  1007.     *p = c;
  1008.  
  1009.     if (opcode == NULL) {
  1010.         the_ins.error = "Unknown operator";
  1011.         the_ins.opcode[0] = NULL;
  1012.         /* the_ins.numo=1; */
  1013.         return;
  1014.     }
  1015.  
  1016.   /* found a legitimate opcode, start matching operands */
  1017.     for(opP= &the_ins.operands[0];*p;opP++) {
  1018.         p = crack_operand (p, opP);
  1019.         if(opP->error) {
  1020.             the_ins.error=opP->error;
  1021.             return;
  1022.         }
  1023.     }
  1024.  
  1025.     opsfound=opP- &the_ins.operands[0];
  1026.     /* This ugly hack is to support the floating pt opcodes in their standard form */
  1027.     /* Essentially, we fake a first enty of type COP#1 */
  1028.     if(opcode->m_operands[0]=='I') {
  1029.         int    n;
  1030.  
  1031.         for(n=opsfound;n>0;--n)
  1032.             the_ins.operands[n]=the_ins.operands[n-1];
  1033.  
  1034.         /* bcopy((char *)(&the_ins.operands[0]),(char *)(&the_ins.operands[1]),opsfound*sizeof(the_ins.operands[0])); */
  1035.         bzero((char *)(&the_ins.operands[0]),sizeof(the_ins.operands[0]));
  1036.         the_ins.operands[0].mode=MSCR;
  1037.         the_ins.operands[0].reg=COPNUM;        /* COP #1 */
  1038.         opsfound++;
  1039.     }
  1040.         /* We've got the operands.  Find an opcode that'll
  1041.            accept them */
  1042.     for(losing=0;;) {
  1043.         if(opsfound!=opcode->m_opnum)
  1044.             losing++;
  1045.         else for(s=opcode->m_operands,opP= &the_ins.operands[0];*s && !losing;s+=2,opP++) {
  1046.                 /* Warning: this switch is huge! */
  1047.                 /* I've tried to organize the cases into  this order:
  1048.                    non-alpha first, then alpha by letter.  lower-case goes directly
  1049.                    before uppercase counterpart. */
  1050.                 /* Code with multiple case ...: gets sorted by the lowest case ...
  1051.                    it belongs to.  I hope this makes sense. */
  1052.             switch(*s) {
  1053.             case '!':
  1054.                 if(opP->mode==MSCR || opP->mode==IMMED ||
  1055.  opP->mode==DREG || opP->mode==AREG || opP->mode==AINC || opP->mode==ADEC || opP->mode==REGLST)
  1056.                     losing++;
  1057.                 break;
  1058.  
  1059.             case '#':
  1060.                 if(opP->mode!=IMMED)
  1061.                      losing++;
  1062.                 else {
  1063.                     long t;
  1064.  
  1065.                     t=get_num(opP->con1,80);
  1066.                     if(s[1]=='b' && !isbyte(t))
  1067.                         losing++;
  1068.                     else if(s[1]=='w' && !isword(t))
  1069.                         losing++;
  1070.                 }
  1071.                 break;
  1072.  
  1073.             case '^':
  1074.             case 'T':
  1075.                 if(opP->mode!=IMMED)
  1076.                     losing++;
  1077.                 break;
  1078.  
  1079.             case '$':
  1080.                 if(opP->mode==MSCR || opP->mode==AREG ||
  1081.  opP->mode==IMMED || opP->reg==PC || opP->reg==ZPC || opP->mode==REGLST)
  1082.                     losing++;
  1083.                 break;
  1084.  
  1085.             case '%':
  1086.                 if(opP->mode==MSCR || opP->reg==PC ||
  1087.  opP->reg==ZPC || opP->mode==REGLST)
  1088.                     losing++;
  1089.                 break;
  1090.  
  1091.  
  1092.             case '&':
  1093.                 if(opP->mode==MSCR || opP->mode==DREG ||
  1094.  opP->mode==AREG || opP->mode==IMMED || opP->reg==PC || opP->reg==ZPC ||
  1095.  opP->mode==AINC || opP->mode==ADEC || opP->mode==REGLST)
  1096.                     losing++;
  1097.                 break;
  1098.  
  1099.             case '*':
  1100.                 if(opP->mode==MSCR || opP->mode==REGLST)
  1101.                     losing++;
  1102.                 break;
  1103.  
  1104.             case '+':
  1105.                 if(opP->mode!=AINC)
  1106.                     losing++;
  1107.                 break;
  1108.  
  1109.             case '-':
  1110.                 if(opP->mode!=ADEC)
  1111.                     losing++;
  1112.                 break;
  1113.  
  1114.             case '/':
  1115.                 if(opP->mode==MSCR || opP->mode==AREG ||
  1116.  opP->mode==AINC || opP->mode==ADEC || opP->mode==IMMED || opP->mode==REGLST)
  1117.                     losing++;
  1118.                 break;
  1119.  
  1120.             case ';':
  1121.                 if(opP->mode==MSCR || opP->mode==AREG || opP->mode==REGLST)
  1122.                     losing++;
  1123.                 break;
  1124.  
  1125.             case '?':
  1126.                 if(opP->mode==MSCR || opP->mode==AREG ||
  1127.  opP->mode==AINC || opP->mode==ADEC || opP->mode==IMMED || opP->reg==PC ||
  1128.  opP->reg==ZPC || opP->mode==REGLST)
  1129.                     losing++;
  1130.                 break;
  1131.  
  1132.             case '@':
  1133.                 if(opP->mode==MSCR || opP->mode==AREG ||
  1134.  opP->mode==IMMED || opP->mode==REGLST)
  1135.                     losing++;
  1136.                 break;
  1137.  
  1138.             case '~':        /* For now! (JF FOO is this right?) */
  1139.                 if(opP->mode==MSCR || opP->mode==DREG ||
  1140.  opP->mode==AREG || opP->mode==IMMED || opP->reg==PC || opP->reg==ZPC || opP->mode==REGLST)
  1141.                     losing++;
  1142.                 break;
  1143.  
  1144.             case 'A':
  1145.                 if(opP->mode!=AREG)
  1146.                     losing++;
  1147.                 break;
  1148.  
  1149.             case 'B':    /* FOO */
  1150.                 if(opP->mode!=ABSL)
  1151.                     losing++;
  1152.                 break;
  1153.  
  1154.             case 'C':
  1155.                 if(opP->mode!=MSCR || opP->reg!=CCR)
  1156.                     losing++;
  1157.                 break;
  1158.  
  1159.             case 'd':    /* FOO This mode is a KLUDGE!! */
  1160.                 if(opP->mode!=AOFF && (opP->mode!=ABSL ||
  1161.  opP->con1->e_beg[0]!='(' || opP->con1->e_end[0]!=')'))
  1162.                     losing++;
  1163.                 break;
  1164.  
  1165.             case 'D':
  1166.                 if(opP->mode!=DREG)
  1167.                     losing++;
  1168.                 break;
  1169.  
  1170.             case 'F':
  1171.                 if(opP->mode!=MSCR || opP->reg<(FPREG+0) || opP->reg>(FPREG+7))
  1172.                     losing++;
  1173.                 break;
  1174.  
  1175.             case 'I':
  1176.                 if(opP->mode!=MSCR || opP->reg<COPNUM ||
  1177.  opP->reg>=COPNUM+7)
  1178.                     losing++;
  1179.                 break;
  1180.  
  1181.             case 'J':
  1182.                 if(opP->mode!=MSCR || opP->reg<USP || opP->reg>MSP)
  1183.                     losing++;
  1184.                 break;
  1185.  
  1186.             case 'k':
  1187.                 if(opP->mode!=IMMED)
  1188.                     losing++;
  1189.                 break;
  1190.  
  1191.             case 'l':
  1192.             case 'L':
  1193.                 if(opP->mode==DREG || opP->mode==AREG || opP->mode==FPREG) {
  1194.                     if(s[1]=='8')
  1195.                         losing++;
  1196.                     else {
  1197.                         opP->mode=REGLST;
  1198.                         opP->reg=1<<(opP->reg-DATA);
  1199.                     }
  1200.                 } else if(opP->mode!=REGLST) {
  1201.                     losing++;
  1202.                 } else if(s[1]=='8' && opP->reg&0x0FFffFF)
  1203.                     losing++;
  1204.                 else if(s[1]=='3' && opP->reg&0x7000000)
  1205.                     losing++;
  1206.                 break;
  1207.  
  1208.             case 'M':
  1209.                 if(opP->mode!=IMMED)
  1210.                     losing++;
  1211.                 else {
  1212.                     long t;
  1213.  
  1214.                     t=get_num(opP->con1,80);
  1215.                     if(!issbyte(t) || isvar(opP->con1))
  1216.                         losing++;
  1217.                 }
  1218.                 break;
  1219.  
  1220.             case 'O':
  1221.                 if(opP->mode!=DREG && opP->mode!=IMMED)
  1222.                     losing++;
  1223.                 break;
  1224.  
  1225.             case 'Q':
  1226.                 if(opP->mode!=IMMED)
  1227.                     losing++;
  1228.                 else {
  1229.                     long t;
  1230.  
  1231.                     t=get_num(opP->con1,80);
  1232.                     if(t<1 || t>8 || isvar(opP->con1))
  1233.                         losing++;
  1234.                 }
  1235.                 break;
  1236.  
  1237.             case 'R':
  1238.                 if(opP->mode!=DREG && opP->mode!=AREG)
  1239.                     losing++;
  1240.                 break;
  1241.  
  1242.             case 's':
  1243.                 if(opP->mode!=MSCR || !(opP->reg==FPI || opP->reg==FPS || opP->reg==FPC))
  1244.                     losing++;
  1245.                 break;
  1246.  
  1247.             case 'S':
  1248.                 if(opP->mode!=MSCR || opP->reg!=SR)
  1249.                     losing++;
  1250.                 break;
  1251.  
  1252.             case 'U':
  1253.                 if(opP->mode!=MSCR || opP->reg!=USP)
  1254.                     losing++;
  1255.                 break;
  1256.  
  1257.             /* JF these are out of order.  We could put them
  1258.                in order if we were willing to put up with
  1259.                bunches of #ifdef m68851s in the code */
  1260. #ifdef m68851
  1261.             /* Memory addressing mode used by pflushr */
  1262.             case '|':
  1263.                 if(opP->mode==MSCR || opP->mode==DREG ||
  1264.  opP->mode==AREG || opP->mode==REGLST)
  1265.                     losing++;
  1266.                 break;
  1267.  
  1268.             case 'f':
  1269.                 if (opP->mode != MSCR || (opP->reg != SFC && opP->reg != DFC))
  1270.                     losing++;
  1271.                 break;
  1272.  
  1273.             case 'P':
  1274.                 if (opP->mode != MSCR || (opP->reg != TC && opP->reg != CAL &&
  1275.                     opP->reg != VAL && opP->reg != SCC && opP->reg != AC))
  1276.                     losing++;
  1277.                 break;
  1278.  
  1279.             case 'V':
  1280.                 if (opP->reg != VAL)
  1281.                     losing++;
  1282.                 break;
  1283.  
  1284.             case 'W':
  1285.                 if (opP->mode != MSCR || (opP->reg != DRP && opP->reg != SRP &&
  1286.                     opP->reg != CRP))
  1287.                     losing++;
  1288.                 break;
  1289.  
  1290.             case 'X':
  1291.                 if (opP->mode != MSCR ||
  1292.                     (!(opP->reg >= BAD && opP->reg <= BAD+7) &&
  1293.                      !(opP->reg >= BAC && opP->reg <= BAC+7)))
  1294.                     losing++;
  1295.                 break;
  1296.  
  1297.             case 'Y':
  1298.                 if (opP->reg != PSR)
  1299.                     losing++;
  1300.                 break;
  1301.  
  1302.             case 'Z':
  1303.                 if (opP->reg != PCSR)
  1304.                     losing++;
  1305.                 break;
  1306. #endif
  1307.             default:
  1308.                 as_fatal("Internal error:  Operand mode %c unknown",*s);
  1309.             }
  1310.         }
  1311.         if(!losing)
  1312.             break;
  1313.         opcode=opcode->m_next;
  1314.         if(!opcode) {        /* Fell off the end */
  1315.             the_ins.error="instruction/operands mismatch";
  1316.             return;
  1317.         }
  1318.         losing=0;
  1319.     }
  1320.     the_ins.args=opcode->m_operands;
  1321.     the_ins.numargs=opcode->m_opnum;
  1322.     the_ins.numo=opcode->m_codenum;
  1323.     the_ins.opcode[0]=getone(opcode);
  1324.     the_ins.opcode[1]=gettwo(opcode);
  1325.  
  1326.     for(s=the_ins.args,opP= &the_ins.operands[0];*s;s+=2,opP++) {
  1327.             /* This switch is a doozy.
  1328.                What the first step; its a big one! */
  1329.         switch(s[0]) {
  1330.  
  1331.         case '*':
  1332.         case '~':
  1333.         case '%':
  1334.         case ';':
  1335.         case '@':
  1336.         case '!':
  1337.         case '&':
  1338.         case '$':
  1339.         case '?':
  1340.         case '/':
  1341. #ifdef m68851
  1342.         case '|':
  1343. #endif
  1344.             switch(opP->mode) {
  1345.             case IMMED:
  1346.                 tmpreg=0x3c;    /* 7.4 */
  1347.                 if(index("bwl",s[1])) nextword=get_num(opP->con1,80);
  1348.                 else nextword=nextword=get_num(opP->con1,0);
  1349.                 if(isvar(opP->con1))
  1350.                     add_fix(s[1],opP->con1,0);
  1351.                 switch(s[1]) {
  1352.                 case 'b':
  1353.                     if(!isbyte(nextword))
  1354.                         opP->error="operand out of range";
  1355.                     addword(nextword);
  1356.                     baseo=0;
  1357.                     break;
  1358.                 case 'w':
  1359.                     if(!isword(nextword))
  1360.                         opP->error="operand out of range";
  1361.                     addword(nextword);
  1362.                     baseo=0;
  1363.                     break;
  1364.                 case 'l':
  1365.                     addword(nextword>>16);
  1366.                     addword(nextword);
  1367.                     baseo=0;
  1368.                     break;
  1369.  
  1370.                 case 'f':
  1371.                     baseo=2;
  1372.                     outro=8;
  1373.                     break;
  1374.                 case 'F':
  1375.                     baseo=4;
  1376.                     outro=11;
  1377.                     break;
  1378.                 case 'x':
  1379.                     baseo=6;
  1380.                     outro=15;
  1381.                     break;
  1382.                 case 'p':
  1383.                     baseo=6;
  1384.                     outro= -1;
  1385.                     break;
  1386.                 default:
  1387.                     as_fatal("Internal error:  Can't decode %c%c",*s,s[1]);
  1388.                 }
  1389.                 if(!baseo)
  1390.                     break;
  1391.  
  1392.                 /* We gotta put out some float */
  1393.                 if(seg(opP->con1)!=SEG_BIG) {
  1394.                     int_to_gen(nextword);
  1395.                     gen_to_words(words,baseo,(long int)outro);
  1396.                     for(wordp=words;baseo--;wordp++)
  1397.                         addword(*wordp);
  1398.                     break;
  1399.                 }        /* Its BIG */
  1400.                 if(offs(opP->con1)>0) {
  1401.                     as_warn("Bignum assumed to be binary bit-pattern");
  1402.                     if(offs(opP->con1)>baseo) {
  1403.                         as_warn("Bignum too big for %c format; truncated",s[1]);
  1404.                         offs(opP->con1)=baseo;
  1405.                     }
  1406.                     baseo-=offs(opP->con1);
  1407.                     for(wordp=generic_bignum+offs(opP->con1)-1;offs(opP->con1)--;--wordp)
  1408.                         addword(*wordp);
  1409.                     while(baseo--)
  1410.                         addword(0);
  1411.                     break;
  1412.                 }
  1413.                 gen_to_words(words,baseo,(long int)outro);
  1414.                 for(wordp=words;baseo--;wordp++)
  1415.                     addword(*wordp);
  1416.                 break;
  1417.             case DREG:
  1418.                 tmpreg=opP->reg-DATA; /* 0.dreg */
  1419.                 break;
  1420.             case AREG:
  1421.                 tmpreg=0x08+opP->reg-ADDR; /* 1.areg */
  1422.                 break;
  1423.             case AINDR:
  1424.                 tmpreg=0x10+opP->reg-ADDR; /* 2.areg */
  1425.                 break;
  1426.             case ADEC:
  1427.                 tmpreg=0x20+opP->reg-ADDR; /* 4.areg */
  1428.                 break;
  1429.             case AINC:
  1430.                 tmpreg=0x18+opP->reg-ADDR; /* 3.areg */
  1431.                 break;
  1432.             case AOFF:
  1433.                 if(opP->reg==PC)
  1434.                     tmpreg=0x3A; /* 7.2 */
  1435.                 else
  1436.                     tmpreg=0x28+opP->reg-ADDR; /* 5.areg */
  1437.                 nextword=get_num(opP->con1,80);
  1438.                 /* Force into index mode.  Hope this works */
  1439.                 if(!issword(nextword)) {
  1440.                     if(opP->reg==PC)
  1441.                         tmpreg=0x3B;    /* 7.3 */
  1442.                     else
  1443.                         tmpreg=0x30+opP->reg-ADDR;    /* 6.areg */
  1444.                     /* addword(0x0171); */
  1445. /* 171 seems to be wrong, and I can't find the 68020 manual, so we'll try 170
  1446.    (which is what the Sun asm seems to generate */
  1447.                     addword(0x0170);
  1448.                     if(isvar(opP->con1))
  1449.                         add_fix('l',opP->con1,0);
  1450.                     addword(nextword>>16);
  1451.                     /* addword(nextword); */
  1452.                 } else if(isvar(opP->con1)) {
  1453.                     if(!flagseen['l']) {
  1454.                         add_fix('w',opP->con1,0);
  1455.                     } else {
  1456.                         tmpreg=0x30+opP->reg-ADDR;
  1457.                         addword(0x0170);
  1458.                         add_fix('l',opP->con1,0);
  1459.                         addword(nextword>>16);
  1460.                     }
  1461.                 }
  1462.                 addword(nextword);
  1463.                 break;
  1464.             case AINDX:
  1465.             case APODX:
  1466.             case AMIND:
  1467.             case APRDX:
  1468.                 nextword=0;
  1469.                 baseo=get_num(opP->con1,80);
  1470.                 outro=get_num(opP->con2,80);
  1471.                     /* Figure out the 'addressing mode' */
  1472.                     /* Also turn on the BASE_DISABLE bit, if needed */
  1473.                 if(opP->reg==PC || opP->reg==ZPC) {
  1474.                     tmpreg=0x3b; /* 7.3 */
  1475.                     if(opP->reg==ZPC)
  1476.                         nextword|=0x80;
  1477.                 } else if(opP->reg==FAIL) {
  1478.                     nextword|=0x80;
  1479.                     tmpreg=0x30;    /* 6.garbage */
  1480.                 } else tmpreg=0x30+opP->reg-ADDR; /* 6.areg */
  1481.  
  1482.                 siz1= (opP->con1) ? opP->con1->e_siz : 0;
  1483.                 siz2= (opP->con2) ? opP->con2->e_siz : 0;
  1484.  
  1485.                     /* Index register stuff */
  1486.                 if(opP->ireg>=DATA+0 && opP->ireg<=ADDR+7) {
  1487.                     nextword|=(opP->ireg-DATA)<<12;
  1488.  
  1489.                     if(opP->isiz==0 || opP->isiz==3)
  1490.                         nextword|=0x800;
  1491.                     switch(opP->imul) {
  1492.                     case 1: break;
  1493.                     case 2: nextword|=0x200; break;
  1494.                     case 4: nextword|=0x400; break;
  1495.                     case 8: nextword|=0x600; break;
  1496.                     default: abort();
  1497.                     }
  1498.                         /* IF its simple, GET US OUT OF HERE! */
  1499.                         /* Must be INDEX, with an index register.  Address register
  1500.                            cannot be ZERO-PC, and either :b was forced, or we know it'll fit */
  1501.                     if(opP->mode==AINDX &&
  1502.  opP->reg!=FAIL && opP->reg!=ZPC && (siz1==1 || (issbyte(baseo) &&
  1503.  !isvar(opP->con1)))) {
  1504.                         nextword +=baseo&0xff;
  1505.                         addword(nextword);
  1506.                         if(isvar(opP->con1))
  1507.                             add_fix('B',opP->con1,0);
  1508.                         break;
  1509.                     }
  1510.                 } else
  1511.                     nextword|=0x40;    /* No index reg */
  1512.                 
  1513.                     /* It aint simple */
  1514.                 nextword|=0x100;
  1515.                     /* If the guy specified a width, we assume that
  1516.                        it is wide enough.  Maybe it isn't.  Ifso, we lose
  1517.                      */
  1518.                 switch(siz1) {
  1519.                 case 0:
  1520.                     if(isvar(opP->con1) || !issword(baseo)) {
  1521.                         siz1=3;
  1522.                         nextword|=0x30;
  1523.                     } else if(baseo==0)
  1524.                         nextword|=0x10;
  1525.                     else {    
  1526.                         nextword|=0x20;
  1527.                         siz1=2;
  1528.                     }
  1529.                     break;
  1530.                 case 1:
  1531.                     as_warn("Byte dispacement won't work.  Defaulting to :w");
  1532.                 case 2:
  1533.                     nextword|=0x20;
  1534.                     break;
  1535.                 case 3:
  1536.                     nextword|=0x30;
  1537.                     break;
  1538.                 }
  1539.  
  1540.                     /* Figure out innner displacement stuff */
  1541.                 if(opP->mode!=AINDX) {
  1542.                     switch(siz2) {
  1543.                     case 0:
  1544.                         if(isvar(opP->con2) || !issword(outro)) {
  1545.                             siz2=3;
  1546.                             nextword|=0x3;
  1547.                         } else if(outro==0)
  1548.                             nextword|=0x1;
  1549.                         else {    
  1550.                             nextword|=0x2;
  1551.                             siz2=2;
  1552.                         }
  1553.                         break;
  1554.                     case 1:
  1555.                         as_warn("Byte dispacement won't work.  Defaulting to :w");
  1556.                     case 2:
  1557.                         nextword|=0x2;
  1558.                         break;
  1559.                     case 3:
  1560.                         nextword|=0x3;
  1561.                         break;
  1562.                     }
  1563.                     if(opP->mode==APODX) nextword|=0x04;
  1564.                     else if(opP->mode==AMIND) nextword|=0x40;
  1565.                 }
  1566.                 addword(nextword);
  1567.  
  1568.                 if(isvar(opP->con1))
  1569.                     add_fix(siz1==3 ? 'l' : 'w',opP->con1,0);
  1570.                 if(siz1==3)
  1571.                     addword(baseo>>16);
  1572.                 if(siz1)
  1573.                     addword(baseo);
  1574.  
  1575.                 if(isvar(opP->con2))
  1576.                     add_fix(siz2==3 ? 'l' : 'w',opP->con2,0);
  1577.                 if(siz2==3)
  1578.                     addword(outro>>16);
  1579.                 if(siz2)
  1580.                     addword(outro);
  1581.  
  1582.                 break;
  1583.  
  1584.             case ABSL:
  1585.                 nextword=get_num(opP->con1,80);
  1586.                 switch(opP->isiz) {
  1587.                 case 0:
  1588.                     if(!isvar(opP->con1) && issword(offs(opP->con1))) {
  1589.                         tmpreg=0x38; /* 7.0 */
  1590.                         addword(nextword);
  1591.                         break;
  1592.                     }
  1593.                     /* Don't generate pc relative code
  1594.                        on 68010 and 68000 */
  1595.                     if(isvar(opP->con1) &&
  1596.                        !subs(opP->con1) &&
  1597.                        seg(opP->con1)==SEG_TEXT &&
  1598.                         now_seg==SEG_TEXT &&
  1599.                        flagseen['m']==0 &&
  1600.                         !index("~%&$?", s[0])) {
  1601.                         tmpreg=0x3A; /* 7.2 */
  1602.                         add_frag(adds(opP->con1),
  1603.                              offs(opP->con1),
  1604.                              TAB(PCREL,SZ_UNDEF));
  1605.                         break;
  1606.                     }
  1607.                 case 3:        /* Fall through into long */
  1608.                     if(isvar(opP->con1))
  1609.                         add_fix('l',opP->con1,0);
  1610.  
  1611.                     tmpreg=0x39;    /* 7.1 mode */
  1612.                     addword(nextword>>16);
  1613.                     addword(nextword);
  1614.                     break;
  1615.  
  1616.                 case 2:        /* Word */
  1617.                     if(isvar(opP->con1))
  1618.                         add_fix('w',opP->con1,0);
  1619.  
  1620.                     tmpreg=0x38;    /* 7.0 mode */
  1621.                     addword(nextword);
  1622.                     break;
  1623.                 }
  1624.                 break;
  1625.             case MSCR:
  1626.             default:
  1627.                 as_warn("unknown/incorrect operand");
  1628.                 /* abort(); */
  1629.             }
  1630.             install_gen_operand(s[1],tmpreg);
  1631.             break;
  1632.  
  1633.         case '#':
  1634.         case '^':
  1635.             switch(s[1]) {    /* JF: I hate floating point! */
  1636.             case 'j':
  1637.                 tmpreg=70;
  1638.                 break;
  1639.             case '8':
  1640.                 tmpreg=20;
  1641.                 break;
  1642.             case 'C':
  1643.                 tmpreg=50;
  1644.                 break;
  1645.             case '3':
  1646.             default:
  1647.                 tmpreg=80;
  1648.                 break;
  1649.             }
  1650.             tmpreg=get_num(opP->con1,tmpreg);
  1651.             if(isvar(opP->con1))
  1652.                 add_fix(s[1],opP->con1,0);
  1653.             switch(s[1]) {
  1654.             case 'b':    /* Danger:  These do no check for
  1655.                        certain types of overflow.
  1656.                        user beware! */
  1657.                 if(!isbyte(tmpreg))
  1658.                     opP->error="out of range";
  1659.                 insop(tmpreg);
  1660.                 if(isvar(opP->con1))
  1661.                     the_ins.reloc[the_ins.nrel-1].n=(opcode->m_codenum)*2;
  1662.                 break;
  1663.             case 'w':
  1664.                 if(!isword(tmpreg))
  1665.                     opP->error="out of range";
  1666.                 insop(tmpreg);
  1667.                 if(isvar(opP->con1))
  1668.                     the_ins.reloc[the_ins.nrel-1].n=(opcode->m_codenum)*2;
  1669.                 break;
  1670.             case 'l':
  1671.                 insop(tmpreg);        /* Because of the way insop works, we put these two out backwards */
  1672.                 insop(tmpreg>>16);
  1673.                 if(isvar(opP->con1))
  1674.                     the_ins.reloc[the_ins.nrel-1].n=(opcode->m_codenum)*2;
  1675.                 break;
  1676.             case '3':
  1677.                 tmpreg&=0xFF;
  1678.             case '8':
  1679.             case 'C':
  1680.                 install_operand(s[1],tmpreg);
  1681.                 break;
  1682.             default:
  1683.                 as_fatal("Internal error:  Unknown mode #%c",s[1]);
  1684.             }
  1685.             break;
  1686.  
  1687.         case '+':
  1688.         case '-':
  1689.         case 'A':
  1690.             install_operand(s[1],opP->reg-ADDR);
  1691.             break;
  1692.  
  1693.         case 'B':
  1694.             tmpreg=get_num(opP->con1,80);
  1695.             switch(s[1]) {
  1696.             case 'g':
  1697.                 if(opP->con1->e_siz) {    /* Deal with fixed size stuff by hand */
  1698.                     switch(opP->con1->e_siz) {
  1699.                     case 1:
  1700.                         add_fix('b',opP->con1,1);
  1701.                         break;
  1702.                     case 2:
  1703.                         add_fix('w',opP->con1,1);
  1704.                         addword(0);
  1705.                         break;
  1706.                     case 3:
  1707.                         add_fix('l',opP->con1,1);
  1708.                         addword(0);
  1709.                         addword(0);
  1710.                         break;
  1711.                     default:
  1712.                         as_fatal("Bad size for expression %d",opP->con1->e_siz);
  1713.                     }
  1714.                 } else if(subs(opP->con1)) {
  1715.                         /* We can't relax it */
  1716.                     the_ins.opcode[the_ins.numo-1]|=0xff;
  1717.                     add_fix('l',opP->con1,1);
  1718.                     addword(0);
  1719.                     addword(0);
  1720.                 } else if(adds(opP->con1)) {
  1721.                     if (flagseen['m'] && 
  1722.                         (the_ins.opcode[0] >= 0x6200) &&
  1723.                         (the_ins.opcode[0] <= 0x6f00)) {
  1724.                       add_frag(adds(opP->con1),offs(opP->con1),TAB(BCC68000,SZ_UNDEF));
  1725.                         } else {
  1726.                     add_frag(adds(opP->con1),offs(opP->con1),TAB(BRANCH,SZ_UNDEF));
  1727.                         }
  1728.                 } else {
  1729.                     /* JF:  This is the WRONG thing to do
  1730.                     add_frag((symbolS *)0,offs(opP->con1),TAB(BRANCH,BYTE)); */
  1731.                     the_ins.opcode[the_ins.numo-1]|=0xff;
  1732.                     add_fix('l',opP->con1,1);
  1733.                     addword(0);
  1734.                     addword(4);
  1735.                 }
  1736.                 break;
  1737.             case 'w':
  1738.                 if(isvar(opP->con1)) {
  1739.                     /* check for DBcc instruction */
  1740.                                     if ((the_ins.opcode[0] & 0xf0f8) ==0x50c8){
  1741.                                             /* size varies if patch */
  1742.                                             /* needed for long form */
  1743.                                             add_frag(adds(opP->con1),offs(opP->con1),TAB(DBCC,SZ_UNDEF));
  1744.                                             break;
  1745.                                         }
  1746.                                         
  1747.                         /* Don't ask! */
  1748.                     opP->con1->e_exp.X_add_number+=2;
  1749.                     add_fix('w',opP->con1,1);
  1750.                 }
  1751.                 addword(0);
  1752.                 break;
  1753.             case 'c':
  1754.                 if(opP->con1->e_siz) {
  1755.                     switch(opP->con1->e_siz) {
  1756.                     case 2:
  1757.                         add_fix('w',opP->con1,1)
  1758.                         addword(0);
  1759.                         break;
  1760.                     case 3:
  1761.                         the_ins.opcode[the_ins.numo-1]|=0x40;
  1762.                         add_fix('l',opP->con1,1);
  1763.                         addword(0);
  1764.                         addword(0);
  1765.                         break;
  1766.                     default:
  1767.                         as_warn("Bad size for offset, must be word or long");
  1768.                         break;
  1769.                     }
  1770.                 } else if(subs(opP->con1)) {
  1771.                     add_fix('l',opP->con1,1);
  1772.                     add_frag((symbolS *)0,(long)0,TAB(FBRANCH,LONG));
  1773.                 } else if(adds(opP->con1)) {
  1774.                     add_frag(adds(opP->con1),offs(opP->con1),TAB(FBRANCH,SZ_UNDEF));
  1775.                 } else {
  1776.                     /* add_frag((symbolS *)0,offs(opP->con1),TAB(FBRANCH,SHORT)); */
  1777.                     the_ins.opcode[the_ins.numo-1]|=0x40;
  1778.                     add_fix('l',opP->con1,1);
  1779.                     addword(0);
  1780.                     addword(4);
  1781.                 }
  1782.                 break;
  1783.             default:
  1784.                 as_fatal("Internal error:  operand type B%c unknown",s[1]);
  1785.             }
  1786.             break;
  1787.  
  1788.         case 'C':        /* Ignore it */
  1789.             break;
  1790.  
  1791.         case 'd':        /* JF this is a kludge */
  1792.             if(opP->mode==AOFF) {
  1793.                 install_operand('s',opP->reg-ADDR);
  1794.             } else {
  1795.                 char *tmpP;
  1796.  
  1797.                 tmpP=opP->con1->e_end-2;
  1798.                 opP->con1->e_beg++;
  1799.                 opP->con1->e_end-=4;    /* point to the , */
  1800.                 baseo=m68k_reg_parse(&tmpP);
  1801.                 if(baseo<ADDR+0 || baseo>ADDR+7) {
  1802.                     as_warn("Unknown address reg, using A0");
  1803.                     baseo=0;
  1804.                 } else baseo-=ADDR;
  1805.                 install_operand('s',baseo);
  1806.             }
  1807.             tmpreg=get_num(opP->con1,80);
  1808.             if(!issword(tmpreg)) {
  1809.                 as_warn("Expression out of range, using 0");
  1810.                 tmpreg=0;
  1811.             }
  1812.             addword(tmpreg);
  1813.             break;
  1814.  
  1815.         case 'D':
  1816.             install_operand(s[1],opP->reg-DATA);
  1817.             break;
  1818.  
  1819.         case 'F':
  1820.             install_operand(s[1],opP->reg-FPREG);
  1821.             break;
  1822.  
  1823.         case 'I':
  1824.             tmpreg=1+opP->reg-COPNUM;
  1825.             if(tmpreg==8)
  1826.                 tmpreg=0;
  1827.             install_operand(s[1],tmpreg);
  1828.             break;
  1829.  
  1830.         case 'J':        /* JF foo */
  1831.             switch(opP->reg) {
  1832.             case SFC:
  1833.                 tmpreg=0;
  1834.                 break;
  1835.             case DFC:
  1836.                 tmpreg=0x001;
  1837.                 break;
  1838.             case CACR:
  1839.                 tmpreg=0x002;
  1840.                 break;
  1841.             case USP:
  1842.                 tmpreg=0x800;
  1843.                 break;
  1844.             case VBR:
  1845.                 tmpreg=0x801;
  1846.                 break;
  1847.             case CAAR:
  1848.                 tmpreg=0x802;
  1849.                 break;
  1850.             case MSP:
  1851.                 tmpreg=0x803;
  1852.                 break;
  1853.             case ISP:
  1854.                 tmpreg=0x804;
  1855.                 break;
  1856.             default:
  1857.                 abort();
  1858.             }
  1859.             install_operand(s[1],tmpreg);
  1860.             break;
  1861.  
  1862.         case 'k':
  1863.             tmpreg=get_num(opP->con1,55);
  1864.             install_operand(s[1],tmpreg&0x7f);
  1865.             break;
  1866.  
  1867.         case 'l':
  1868.             tmpreg=opP->reg;
  1869.             if(s[1]=='w') {
  1870.                 if(tmpreg&0x7FF0000)
  1871.                     as_warn("Floating point register in register list");
  1872.                 insop(reverse_16_bits(tmpreg));
  1873.             } else {
  1874.                 if(tmpreg&0x700FFFF)
  1875.                     as_warn("Wrong register in floating-point reglist");
  1876.                 install_operand(s[1],reverse_8_bits(tmpreg>>16));
  1877.             }
  1878.             break;
  1879.  
  1880.         case 'L':
  1881.             tmpreg=opP->reg;
  1882.             if(s[1]=='w') {
  1883.                 if(tmpreg&0x7FF0000)
  1884.                     as_warn("Floating point register in register list");
  1885.                 insop(tmpreg);
  1886.             } else if(s[1]=='8') {
  1887.                 if(tmpreg&0x0FFFFFF)
  1888.                     as_warn("incorrect register in reglist");
  1889.                 install_operand(s[1],tmpreg>>24);
  1890.             } else {
  1891.                 if(tmpreg&0x700FFFF)
  1892.                     as_warn("wrong register in floating-point reglist");
  1893.                 else
  1894.                     install_operand(s[1],tmpreg>>16);
  1895.             }
  1896.             break;
  1897.  
  1898.         case 'M':
  1899.             install_operand(s[1],get_num(opP->con1,60));
  1900.             break;
  1901.  
  1902.         case 'O':
  1903.             tmpreg= (opP->mode==DREG)
  1904.                 ? 0x20+opP->reg-DATA
  1905.                 : (get_num(opP->con1,40)&0x1F);
  1906.             install_operand(s[1],tmpreg);
  1907.             break;
  1908.  
  1909.         case 'Q':
  1910.             tmpreg=get_num(opP->con1,10);
  1911.             if(tmpreg==8)
  1912.                 tmpreg=0;
  1913.             install_operand(s[1],tmpreg);
  1914.             break;
  1915.  
  1916.         case 'R':
  1917.             /* This depends on the fact that ADDR registers are
  1918.                eight more than their corresponding DATA regs, so
  1919.                the result will have the ADDR_REG bit set */
  1920.             install_operand(s[1],opP->reg-DATA);
  1921.             break;
  1922.  
  1923.         case 's':
  1924.             if(opP->reg==FPI) tmpreg=0x1;
  1925.             else if(opP->reg==FPS) tmpreg=0x2;
  1926.             else if(opP->reg==FPC) tmpreg=0x4;
  1927.             else abort();
  1928.             install_operand(s[1],tmpreg);
  1929.             break;
  1930.  
  1931.         case 'S':    /* Ignore it */
  1932.             break;
  1933.  
  1934.         case 'T':
  1935.             install_operand(s[1],get_num(opP->con1,30));
  1936.             break;
  1937.  
  1938.         case 'U':    /* Ignore it */
  1939.             break;
  1940.  
  1941. #ifdef m68851
  1942.             /* JF: These are out of order, I fear. */
  1943.         case 'f':
  1944.             switch (opP->reg) {
  1945.             case SFC:
  1946.                 tmpreg=0;
  1947.                 break;
  1948.             case DFC:
  1949.                 tmpreg=1;
  1950.                 break;
  1951.             default:
  1952.                 abort();
  1953.             }
  1954.             install_operand(s[1],tmpreg);
  1955.             break;
  1956.  
  1957.         case 'P':
  1958.             switch(opP->reg) {
  1959.             case TC:
  1960.                 tmpreg=0;
  1961.                 break;
  1962.             case CAL:
  1963.                 tmpreg=4;
  1964.                 break;
  1965.             case VAL:
  1966.                 tmpreg=5;
  1967.                 break;
  1968.             case SCC:
  1969.                 tmpreg=6;
  1970.                 break;
  1971.             case AC:
  1972.                 tmpreg=7;
  1973.                 break;
  1974.             default:
  1975.                 abort();
  1976.             }
  1977.             install_operand(s[1],tmpreg);
  1978.             break;
  1979.  
  1980.         case 'V':
  1981.             if (opP->reg == VAL)
  1982.                 break;
  1983.             abort();
  1984.  
  1985.         case 'W':
  1986.             switch(opP->reg) {
  1987.  
  1988.             case DRP:
  1989.                 tmpreg=1;
  1990.                 break;
  1991.             case SRP:
  1992.                 tmpreg=2;
  1993.                 break;
  1994.             case CRP:
  1995.                 tmpreg=3;
  1996.                 break;
  1997.             default:
  1998.                 abort();
  1999.             }
  2000.             install_operand(s[1],tmpreg);
  2001.             break;
  2002.  
  2003.         case 'X':
  2004.             switch (opP->reg) {
  2005.             case BAD: case BAD+1: case BAD+2: case BAD+3:
  2006.             case BAD+4: case BAD+5: case BAD+6: case BAD+7:
  2007.                 tmpreg = (4 << 10) | ((opP->reg - BAD) << 2);
  2008.                 break;
  2009.  
  2010.             case BAC: case BAC+1: case BAC+2: case BAC+3:
  2011.             case BAC+4: case BAC+5: case BAC+6: case BAC+7:
  2012.                 tmpreg = (5 << 10) | ((opP->reg - BAC) << 2);
  2013.                 break;
  2014.  
  2015.             default:
  2016.                 abort();
  2017.             }
  2018.             install_operand(s[1], tmpreg);
  2019.             break;
  2020.         case 'Y':
  2021.             if (opP->reg == PSR)
  2022.                 break;
  2023.             abort();
  2024.  
  2025.         case 'Z':
  2026.             if (opP->reg == PCSR)
  2027.                 break;
  2028.             abort;
  2029. #endif /* m68851 */
  2030.         default:
  2031.             as_fatal("Internal error:  Operand type %c unknown",s[0]);
  2032.         }
  2033.     }
  2034.     /* By the time whe get here (FINALLY) the_ins contains the complete
  2035.        instruction, ready to be emitted. . . */
  2036. }
  2037.  
  2038. int
  2039. get_regs(i,str,opP)
  2040. struct m68k_op *opP;
  2041. char *str;
  2042. {
  2043.     /*                 26, 25, 24, 23-16,  15-8, 0-7 */
  2044.     /* Low order 24 bits encoded fpc,fps,fpi,fp7-fp0,a7-a0,d7-d0 */
  2045.     unsigned long int cur_regs = 0;
  2046.     int    reg1,
  2047.         reg2;
  2048.  
  2049. #define ADD_REG(x)    {     if(x==FPI) cur_regs|=(1<<24);\
  2050.              else if(x==FPS) cur_regs|=(1<<25);\
  2051.              else if(x==FPC) cur_regs|=(1<<26);\
  2052.              else cur_regs|=(1<<(x-1));  }
  2053.  
  2054.     reg1=i;
  2055.     for(;;) {
  2056.         if(*str=='/') {
  2057.             ADD_REG(reg1);
  2058.             str++;
  2059.         } else if(*str=='-') {
  2060.             str++;
  2061.             reg2=m68k_reg_parse(&str);
  2062.             if(reg2<DATA || reg2>=FPREG+8 || reg1==FPI || reg1==FPS || reg1==FPC) {
  2063.                 opP->error="unknown register in register list";
  2064.                 return FAIL;
  2065.             }
  2066.             while(reg1<=reg2) {
  2067.                 ADD_REG(reg1);
  2068.                 reg1++;
  2069.             }
  2070.             if(*str=='\0')
  2071.                 break;
  2072.         } else if(*str=='\0') {
  2073.             ADD_REG(reg1);
  2074.             break;
  2075.         } else {
  2076.             opP->error="unknow character in register list";
  2077.             return FAIL;
  2078.         }
  2079. /* DJA -- Bug Fix.  Did't handle d1-d2/a1 until the following instruction was added */
  2080.         if (*str=='/')
  2081.           str ++;
  2082.         reg1=m68k_reg_parse(&str);
  2083.         if((reg1<DATA || reg1>=FPREG+8) && !(reg1==FPI || reg1==FPS || reg1==FPC)) {
  2084.             opP->error="unknown register in register list";
  2085.             return FAIL;
  2086.         }
  2087.     }
  2088.     opP->reg=cur_regs;
  2089.     return OK;
  2090. }
  2091.  
  2092. int
  2093. reverse_16_bits(in)
  2094. int in;
  2095. {
  2096.     int out=0;
  2097.     int n;
  2098.  
  2099.     static int mask[16] = {
  2100. 0x0001,0x0002,0x0004,0x0008,0x0010,0x0020,0x0040,0x0080,
  2101. 0x0100,0x0200,0x0400,0x0800,0x1000,0x2000,0x4000,0x8000
  2102.     };
  2103.     for(n=0;n<16;n++) {
  2104.         if(in&mask[n])
  2105.             out|=mask[15-n];
  2106.     }
  2107.     return out;
  2108. }
  2109.  
  2110. int
  2111. reverse_8_bits(in)
  2112. int in;
  2113. {
  2114.     int out=0;
  2115.     int n;
  2116.  
  2117.     static int mask[8] = {
  2118. 0x0001,0x0002,0x0004,0x0008,0x0010,0x0020,0x0040,0x0080,
  2119.     };
  2120.  
  2121.     for(n=0;n<8;n++) {
  2122.         if(in&mask[n])
  2123.             out|=mask[7-n];
  2124.     }
  2125.     return out;
  2126. }
  2127.     
  2128. void
  2129. install_operand(mode,val)
  2130. int mode;
  2131. int val;
  2132. {
  2133.     switch(mode) {
  2134.     case 's':
  2135.         the_ins.opcode[0]|=val & 0xFF;    /* JF FF is for M kludge */
  2136.         break;
  2137.     case 'd':
  2138.         the_ins.opcode[0]|=val<<9;
  2139.         break;
  2140.     case '1':
  2141.         the_ins.opcode[1]|=val<<12;
  2142.         break;
  2143.     case '2':
  2144.         the_ins.opcode[1]|=val<<6;
  2145.         break;
  2146.     case '3':
  2147.         the_ins.opcode[1]|=val;
  2148.         break;
  2149.     case '4':
  2150.         the_ins.opcode[2]|=val<<12;
  2151.         break;
  2152.     case '5':
  2153.         the_ins.opcode[2]|=val<<6;
  2154.         break;
  2155.     case '6':
  2156.             /* DANGER!  This is a hack to force cas2l and cas2w cmds
  2157.                to be three words long! */
  2158.         the_ins.numo++;
  2159.         the_ins.opcode[2]|=val;
  2160.         break;
  2161.     case '7':
  2162.         the_ins.opcode[1]|=val<<7;
  2163.         break;
  2164.     case '8':
  2165.         the_ins.opcode[1]|=val<<10;
  2166.         break;
  2167. #ifdef m68851
  2168.     case '9':
  2169.         the_ins.opcode[1]|=val<<5;
  2170.         break;
  2171. #endif
  2172.         
  2173.     case 't':
  2174.         the_ins.opcode[1]|=(val<<10)|(val<<7);
  2175.         break;
  2176.     case 'D':
  2177.         the_ins.opcode[1]|=(val<<12)|val;
  2178.         break;
  2179.     case 'g':
  2180.         the_ins.opcode[0]|=val=0xff;
  2181.         break;
  2182.     case 'i':
  2183.         the_ins.opcode[0]|=val<<9;
  2184.         break;
  2185.     case 'C':
  2186.         the_ins.opcode[1]|=val;
  2187.         break;
  2188.     case 'j':
  2189.         the_ins.opcode[1]|=val;
  2190.         the_ins.numo++;        /* What a hack */
  2191.         break;
  2192.     case 'k':
  2193.         the_ins.opcode[1]|=val<<4;
  2194.         break;
  2195.     case 'b':
  2196.     case 'w':
  2197.     case 'l':
  2198.         break;
  2199.     case 'c':
  2200.     default:
  2201.         abort();
  2202.     }
  2203. }
  2204.  
  2205. void
  2206. install_gen_operand(mode,val)
  2207. int mode;
  2208. int val;
  2209. {
  2210.     switch(mode) {
  2211.     case 's':
  2212.         the_ins.opcode[0]|=val;
  2213.         break;
  2214.     case 'd':
  2215.             /* This is a kludge!!! */
  2216.         the_ins.opcode[0]|=(val&0x07)<<9|(val&0x38)<<3;
  2217.         break;
  2218.     case 'b':
  2219.     case 'w':
  2220.     case 'l':
  2221.     case 'f':
  2222.     case 'F':
  2223.     case 'x':
  2224.     case 'p':
  2225.         the_ins.opcode[0]|=val;
  2226.         break;
  2227.         /* more stuff goes here */
  2228.     default:
  2229.         abort();
  2230.     }
  2231. }
  2232.  
  2233. char *
  2234. crack_operand(str,opP)
  2235. register char *str;
  2236. register struct m68k_op *opP;
  2237. {
  2238.     register int parens;
  2239.     register int c;
  2240.     register char *beg_str;
  2241.  
  2242.     if(!str) {
  2243.         return str;
  2244.     }
  2245.     beg_str=str;
  2246.     for(parens=0;*str && (parens>0 || notend(str));str++) {
  2247.         if(*str=='(') parens++;
  2248.         else if(*str==')') {
  2249.             if(!parens) {        /* ERROR */
  2250.                 opP->error="Extra )";
  2251.                 return str;
  2252.             }
  2253.             --parens;
  2254.         }
  2255.     }
  2256.     if(!*str && parens) {        /* ERROR */
  2257.         opP->error="Missing )";
  2258.         return str;
  2259.     }
  2260.     c= *str;
  2261.     *str='\0';
  2262.     if(m68k_ip_op(beg_str,opP)==FAIL) {
  2263.         *str=c;
  2264.         return str;
  2265.     }
  2266.     *str=c;
  2267.     if(c=='}')
  2268.         c= *++str;        /* JF bitfield hack */
  2269.     if(c) {
  2270.          c= *++str;
  2271.         if(!c)
  2272.             as_warn("Missing operand");
  2273.     }
  2274.     return str;
  2275. }
  2276.  
  2277. /* See the comment up above where the #define notend(... is */
  2278. #if 0
  2279. notend(s)
  2280. char *s;
  2281. {
  2282.     if(*s==',') return 0;
  2283.     if(*s=='{' || *s=='}')
  2284.         return 0;
  2285.     if(*s!=':') return 1;
  2286.         /* This kludge here is for the division cmd, which is a kludge */
  2287.     if(index("aAdD#",s[1])) return 0;
  2288.     return 1;
  2289. }
  2290. #endif
  2291.  
  2292. /* This is the guts of the machine-dependent assembler.  STR points to a
  2293.    machine dependent instruction.  This funciton is supposed to emit
  2294.    the frags/bytes it assembles to.
  2295.  */
  2296. void
  2297. md_assemble(str)
  2298. char *str;
  2299. {
  2300.     char *er;
  2301.     short    *fromP;
  2302.     char    *toP;
  2303.     int    m,n;
  2304.     char    *to_beg_P;
  2305.     int    shorts_this_frag;
  2306.  
  2307.     bzero((char *)(&the_ins),sizeof(the_ins));    /* JF for paranoia sake */
  2308.     m68_ip(str);
  2309.     er=the_ins.error;
  2310.     if(!er) {
  2311.         for(n=the_ins.numargs;n;--n)
  2312.             if(the_ins.operands[n].error) {
  2313.                 er=the_ins.operands[n].error;
  2314.                 break;
  2315.             }
  2316.     }
  2317.     if(er) {
  2318.         as_warn("\"%s\" -- Statement '%s' ignored",er,str);
  2319.         return;
  2320.     }
  2321.  
  2322.     if(the_ins.nfrag==0) {    /* No frag hacking involved; just put it out */
  2323.         toP=frag_more(2*the_ins.numo);
  2324.         fromP= &the_ins.opcode[0];
  2325.         for(m=the_ins.numo;m;--m) {
  2326.             md_number_to_chars(toP,(long)(*fromP),2);
  2327.             toP+=2;
  2328.             fromP++;
  2329.         }
  2330.             /* put out symbol-dependent info */
  2331.         for(m=0;m<the_ins.nrel;m++) {
  2332.             switch(the_ins.reloc[m].wid) {
  2333.             case 'B':
  2334.                 n=1;
  2335.                 break;
  2336.             case 'b':
  2337.                 n=1;
  2338.                 break;
  2339.             case 'w':
  2340.                 n=2;
  2341.                 break;
  2342.             case 'l':
  2343.                 n=4;
  2344.                 break;
  2345.             default:
  2346.                 as_fatal("confusing width %c",the_ins.reloc[m].wid);
  2347.             }
  2348.  
  2349.             fix_new(frag_now,
  2350.                 (toP-frag_now->fr_literal)-the_ins.numo*2+the_ins.reloc[m].n,
  2351.                 n,
  2352.                 the_ins.reloc[m].add,
  2353.                 the_ins.reloc[m].sub,
  2354.                 the_ins.reloc[m].off,
  2355.                 the_ins.reloc[m].pcrel);
  2356.         }
  2357.         return;
  2358.     }
  2359.  
  2360.         /* There's some frag hacking */
  2361.     for(n=0,fromP= &the_ins.opcode[0];n<the_ins.nfrag;n++) {
  2362.         int wid;
  2363.  
  2364.         if(n==0) wid=2*the_ins.fragb[n].fragoff;
  2365.         else wid=2*(the_ins.numo-the_ins.fragb[n-1].fragoff);
  2366.         toP=frag_more(wid);
  2367.         to_beg_P=toP;
  2368.         shorts_this_frag=0;
  2369.         for(m=wid/2;m;--m) {
  2370.             md_number_to_chars(toP,(long)(*fromP),2);
  2371.             toP+=2;
  2372.             fromP++;
  2373.             shorts_this_frag++;
  2374.         }
  2375.         for(m=0;m<the_ins.nrel;m++) {
  2376.             if((the_ins.reloc[m].n)>= 2*shorts_this_frag /* 2*the_ins.fragb[n].fragoff */) {
  2377.                 the_ins.reloc[m].n-= 2*shorts_this_frag /* 2*the_ins.fragb[n].fragoff */;
  2378.                 break;
  2379.             }
  2380.             wid=the_ins.reloc[m].wid;
  2381.             if(wid==0)
  2382.                 continue;
  2383.             the_ins.reloc[m].wid=0;
  2384.             wid = (wid=='b') ? 1 : (wid=='w') ? 2 : (wid=='l') ? 4 : 4000;
  2385.  
  2386.             fix_new(frag_now,
  2387.                 (toP-frag_now->fr_literal)-the_ins.numo*2+the_ins.reloc[m].n,
  2388.                 wid,
  2389.                 the_ins.reloc[m].add,
  2390.                 the_ins.reloc[m].sub,
  2391.                 the_ins.reloc[m].off,
  2392.                 the_ins.reloc[m].pcrel);
  2393.         }
  2394.         know(the_ins.fragb[n].fadd);
  2395.                 (void)frag_var(rs_machine_dependent,10,0,(relax_substateT)(the_ins.fragb[n].fragty),
  2396.  the_ins.fragb[n].fadd,the_ins.fragb[n].foff,to_beg_P);
  2397.     }
  2398.     n=(the_ins.numo-the_ins.fragb[n-1].fragoff);
  2399.     shorts_this_frag=0;
  2400.     if(n) {
  2401.         toP=frag_more(n*sizeof(short));
  2402.         while(n--) {
  2403.             md_number_to_chars(toP,(long)(*fromP),2);
  2404.             toP+=2;
  2405.             fromP++;
  2406.             shorts_this_frag++;
  2407.         }
  2408.     }
  2409.     for(m=0;m<the_ins.nrel;m++) {
  2410.         int wid;
  2411.  
  2412.         wid=the_ins.reloc[m].wid;
  2413.         if(wid==0)
  2414.             continue;
  2415.         the_ins.reloc[m].wid=0;
  2416.         wid = (wid=='b') ? 1 : (wid=='w') ? 2 : (wid=='l') ? 4 : 4000;
  2417.  
  2418.         fix_new(frag_now,
  2419.             (the_ins.reloc[m].n + toP-frag_now->fr_literal)-/* the_ins.numo */ shorts_this_frag*2,
  2420.             wid,
  2421.             the_ins.reloc[m].add,
  2422.             the_ins.reloc[m].sub,
  2423.             the_ins.reloc[m].off,
  2424.             the_ins.reloc[m].pcrel);
  2425.     }
  2426. }
  2427.  
  2428. /* This function is called once, at assembler startup time.  This should
  2429.    set up all the tables, etc that the MD part of the assembler needs
  2430.  */
  2431. void
  2432. md_begin()
  2433. {
  2434. /*
  2435.  * md_begin -- set up hash tables with 68000 instructions.
  2436.  * similar to what the vax assembler does.  ---phr
  2437.  */
  2438.     /* RMS claims the thing to do is take the m68k-opcode.h table, and make
  2439.        a copy of it at runtime, adding in the information we want but isn't
  2440.        there.  I think it'd be better to have an awk script hack the table
  2441.        at compile time.  Or even just xstr the table and use it as-is.  But
  2442.        my lord ghod hath spoken, so we do it this way.  Excuse the ugly var
  2443.        names.  */
  2444.  
  2445.     register struct m68k_opcode *ins;
  2446.     register struct m68_incant *hack,
  2447.         *slak;
  2448.     register char *retval = 0;        /* empty string, or error msg text */
  2449.     register int i;
  2450.     register char c;
  2451.  
  2452.     if ((op_hash = hash_new()) == NULL)
  2453.         as_fatal("Virtual memory exhausted");
  2454.  
  2455.     obstack_begin(&robyn,4000);
  2456.     for (ins = m68k_opcodes; ins < endop; ins++) {
  2457.         hack=slak=(struct m68_incant *)obstack_alloc(&robyn,sizeof(struct m68_incant));
  2458.         do {
  2459.             slak->m_operands=ins->args;
  2460.             slak->m_opnum=strlen(slak->m_operands)/2;
  2461.             slak->m_opcode=ins->opcode;
  2462.                 /* This is kludgey */
  2463.             slak->m_codenum=((ins->match)&0xffffL) ? 2 : 1;
  2464.             if((ins+1)!=endop && !strcmp(ins->name,(ins+1)->name)) {
  2465.                 slak->m_next=(struct m68_incant *)
  2466. obstack_alloc(&robyn,sizeof(struct m68_incant));
  2467.                 ins++;
  2468.             } else
  2469.                 slak->m_next=0;
  2470.             slak=slak->m_next;
  2471.         } while(slak);
  2472.         
  2473.         retval = hash_insert (op_hash, ins->name,(char *)hack);
  2474.             /* Didn't his mommy tell him about null pointers? */
  2475.         if(retval && *retval)
  2476.             as_fatal("Internal Error:  Can't hash %s: %s",ins->name,retval);
  2477.     }
  2478.  
  2479.     for (i = 0; i < sizeof(mklower_table) ; i++)
  2480.         mklower_table[i] = (isupper(c = (char) i)) ? tolower(c) : c;
  2481.  
  2482.     for (i = 0 ; i < sizeof(notend_table) ; i++) {
  2483.         notend_table[i] = 0;
  2484.         alt_notend_table[i] = 0;
  2485.     }
  2486.     notend_table[','] = 1;
  2487.     notend_table['{'] = 1;
  2488.     notend_table['}'] = 1;
  2489.     alt_notend_table['a'] = 1;
  2490.     alt_notend_table['A'] = 1;
  2491.     alt_notend_table['d'] = 1;
  2492.     alt_notend_table['D'] = 1;
  2493.     alt_notend_table['#'] = 1;
  2494. }
  2495.  
  2496. #if 0
  2497. #define notend(s) ((*s == ',' || *s == '}' || *s == '{' \
  2498.                    || (*s == ':' && index("aAdD#", s[1]))) \
  2499.                ? 0 : 1)
  2500. #endif
  2501.  
  2502. /* This funciton is called once, before the assembler exits.  It is
  2503.    supposed to do any final cleanup for this part of the assembler.
  2504.  */
  2505. void
  2506. md_end()
  2507. {
  2508. }
  2509.  
  2510. #define MAX_LITTLENUMS 6
  2511.  
  2512. /* Turn a string in input_line_pointer into a floating point constant of type
  2513.    type, and store the appropriate bytes in *litP.  The number of LITTLENUMS
  2514.    emitted is stored in *sizeP .  An error message is returned, or NULL on OK.
  2515.  */
  2516. char *
  2517. md_atof(type,litP,sizeP)
  2518. char type;
  2519. char *litP;
  2520. int *sizeP;
  2521. {
  2522.     int    prec;
  2523.     LITTLENUM_TYPE words[MAX_LITTLENUMS];
  2524.     LITTLENUM_TYPE *wordP;
  2525.     char    *t;
  2526.     char    *atof_m68k();
  2527.  
  2528.     switch(type) {
  2529.     case 'f':
  2530.     case 'F':
  2531.     case 's':
  2532.     case 'S':
  2533.         prec = 2;
  2534.         break;
  2535.  
  2536.     case 'd':
  2537.     case 'D':
  2538.     case 'r':
  2539.     case 'R':
  2540.         prec = 4;
  2541.         break;
  2542.  
  2543.     case 'x':
  2544.     case 'X':
  2545.         prec = 6;
  2546.         break;
  2547.  
  2548.     case 'p':
  2549.     case 'P':
  2550.         prec = 6;
  2551.         break;
  2552.  
  2553.     default:
  2554.         *sizeP=0;
  2555.         return "Bad call to MD_ATOF()";
  2556.     }
  2557.     t=atof_m68k(input_line_pointer,type,words);
  2558.     if(t)
  2559.         input_line_pointer=t;
  2560.  
  2561.     *sizeP=prec * sizeof(LITTLENUM_TYPE);
  2562.     for(wordP=words;prec--;) {
  2563.         md_number_to_chars(litP,(long)(*wordP++),sizeof(LITTLENUM_TYPE));
  2564.         litP+=sizeof(LITTLENUM_TYPE);
  2565.     }
  2566.     return "";    /* Someone should teach Dean about null pointers */
  2567. }
  2568.  
  2569. /* Turn an integer of n bytes (in val) into a stream of bytes appropriate
  2570.    for use in the a.out file, and stores them in the array pointed to by buf.
  2571.    This knows about the endian-ness of the target machine and does
  2572.    THE RIGHT THING, whatever it is.  Possible values for n are 1 (byte)
  2573.    2 (short) and 4 (long)  Floating numbers are put out as a series of
  2574.    LITTLENUMS (shorts, here at least)
  2575.  */
  2576. void
  2577. md_number_to_chars(buf,val,n)
  2578. char    *buf;
  2579. long    val;
  2580. int n;
  2581. {
  2582.     switch(n) {
  2583.     case 1:
  2584.         *buf++=val;
  2585.         break;
  2586.     case 2:
  2587.         *buf++=(val>>8);
  2588.         *buf++=val;
  2589.         break;
  2590.     case 4:
  2591.         *buf++=(val>>24);
  2592.         *buf++=(val>>16);
  2593.         *buf++=(val>>8);
  2594.         *buf++=val;
  2595.         break;
  2596.     default:
  2597.         abort();
  2598.     }
  2599. }
  2600.  
  2601. void
  2602. md_number_to_imm(buf,val,n)
  2603. char *buf;
  2604. long val;
  2605. int n;
  2606. {
  2607.     switch(n) {
  2608.     case 1:
  2609.         *buf++=val;
  2610.         break;
  2611.     case 2:
  2612.         *buf++=(val>>8);
  2613.         *buf++=val;
  2614.         break;
  2615.     case 4:
  2616.         *buf++=(val>>24);
  2617.         *buf++=(val>>16);
  2618.         *buf++=(val>>8);
  2619.         *buf++=val;
  2620.         break;
  2621.     default:
  2622.         abort();
  2623.     }
  2624. }
  2625.  
  2626. void
  2627. md_number_to_disp(buf,val,n)
  2628. char    *buf;
  2629. long    val;
  2630. int n;
  2631. {
  2632.     abort();
  2633. }
  2634.  
  2635. void
  2636. md_number_to_field(buf,val,fix)
  2637. char *buf;
  2638. long val;
  2639. #ifdef __STDC__
  2640. void *fix;
  2641. #else
  2642. char *fix;
  2643. #endif
  2644. {
  2645.     abort();
  2646. }
  2647.  
  2648.  
  2649. /* *fragP has been relaxed to its final size, and now needs to have
  2650.    the bytes inside it modified to conform to the new size  There is UGLY
  2651.    MAGIC here. ..
  2652.  */
  2653. void
  2654. md_convert_frag(fragP)
  2655. register fragS *fragP;
  2656. {
  2657.   long disp;
  2658.   long ext;
  2659.  
  2660.   /* Address in gas core of the place to store the displacement.  */
  2661.   register char *buffer_address = fragP -> fr_fix + fragP -> fr_literal;
  2662.   /* Address in object code of the displacement.  */
  2663.   register int object_address = fragP -> fr_fix + fragP -> fr_address;
  2664.  
  2665.   know(fragP->fr_symbol);
  2666.  
  2667.   /* The displacement of the address, from current location.  */
  2668.   disp = (fragP->fr_symbol->sy_value + fragP->fr_offset) - object_address;
  2669.  
  2670.   switch(fragP->fr_subtype) {
  2671.   case TAB(BCC68000,BYTE):
  2672.   case TAB(BRANCH,BYTE):
  2673.     know(issbyte(disp));
  2674.     if(disp==0)
  2675.       as_warn("short branch with zero offset: use :w");
  2676.     fragP->fr_opcode[1]=disp;
  2677.     ext=0;
  2678.     break;
  2679.   case TAB(DBCC,SHORT):
  2680.     know(issword(disp));
  2681.     ext=2;
  2682.     break;
  2683.   case TAB(BCC68000,SHORT):
  2684.   case TAB(BRANCH,SHORT):
  2685.     know(issword(disp));
  2686.     fragP->fr_opcode[1]=0x00;
  2687.     ext=2;
  2688.     break;
  2689.   case TAB(BRANCH,LONG):
  2690.     if(flagseen['m']) {
  2691.       if(fragP->fr_opcode[0]==0x61) {
  2692.     fragP->fr_opcode[0]= 0x4E;
  2693.     fragP->fr_opcode[1]= 0xB9;    /* JBSR with ABSL LONG offset */
  2694.     subseg_change(SEG_TEXT, 0);
  2695.     fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0, fragP->fr_offset, 0);
  2696.     fragP->fr_fix+=4;
  2697.     ext=0;
  2698.       } else if(fragP->fr_opcode[0]==0x60) {
  2699.         fragP->fr_opcode[0]= 0x4E;
  2700.         fragP->fr_opcode[1]= 0xF9;      /* JMP  with ABSL LONG offset */
  2701.         subseg_change(SEG_TEXT, 0);
  2702.         fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0, fragP->fr_offset,0);
  2703.         fragP->fr_fix+=4;
  2704.         ext=0;
  2705.       }else {
  2706.         as_warn("Long branch offset not supported.");
  2707.       }
  2708.     } else {
  2709.       fragP->fr_opcode[1]=0xff;
  2710.       ext=4;
  2711.     }
  2712.     break;
  2713.   case TAB(BCC68000,LONG):
  2714.     {
  2715.     /* only Bcc 68000 instructions can come here */
  2716.         /* change bcc into b!cc/jmp absl long */
  2717.     fragP->fr_opcode[0] ^= 0x01; /* invert bcc */
  2718.         fragP->fr_opcode[1] = 0x6;   /* branch offset = 6 */
  2719.         fragP->fr_opcode[2] = 0x4e;  /* put in jmp long (0x4ef9) */ 
  2720.         fragP->fr_opcode[3] = 0xf9;  
  2721.         fragP->fr_fix += 2;         /* account for jmp instruction */
  2722.         subseg_change(SEG_TEXT,0);
  2723.         fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0, 
  2724.                      fragP->fr_offset,0);
  2725.         fragP->fr_fix += 4;
  2726.         ext=0;
  2727.     }
  2728.     break;
  2729.   case TAB(DBCC,LONG):
  2730.     {
  2731.         /* only DBcc 68000 instructions can come here */
  2732.         /* change dbcc into dbcc/jmp absl long */
  2733.         fragP->fr_opcode[2] = 0x00;  /* branch offset = 4 */
  2734.         fragP->fr_opcode[3] = 0x04;  
  2735.         fragP->fr_opcode[4] = 0x60;  /* put in bra pc+6 */ 
  2736.         fragP->fr_opcode[5] = 0x06;  
  2737.         fragP->fr_opcode[6] = 0x4e;  /* put in jmp long (0x4ef9) */ 
  2738.         fragP->fr_opcode[7] = 0xf9;  
  2739.  
  2740.         fragP->fr_fix += 6;         /* account for bra/jmp instructions */
  2741.         subseg_change(SEG_TEXT,0);
  2742.         fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0, 
  2743.                      fragP->fr_offset,0);
  2744.         fragP->fr_fix += 4;
  2745.         ext=0;
  2746.     }
  2747.     break;
  2748.   case TAB(FBRANCH,SHORT):
  2749.     know((fragP->fr_opcode[1]&0x40)==0);
  2750.     ext=2;
  2751.     break;
  2752.   case TAB(FBRANCH,LONG):
  2753.     fragP->fr_opcode[1]|=0x40;    /* Turn on LONG bit */
  2754.     ext=4;
  2755.     break;
  2756.   case TAB(PCREL,SHORT):
  2757.     ext=2;
  2758.     break;
  2759.   case TAB(PCREL,LONG):
  2760.     /* The thing to do here is force it to ABSOLUTE LONG, since
  2761.        PCREL is really trying to shorten an ABSOLUTE address anyway */
  2762.     /* JF FOO This code has not been tested */
  2763.     subseg_change(SEG_TEXT,0);
  2764.     fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0, fragP->fr_offset, 0);
  2765.     if((fragP->fr_opcode[1] & 0x3F) != 0x3A)
  2766.         as_warn("Internal error (long PC-relative operand) for insn 0x%04lx at 0x%lx",
  2767.             fragP->fr_opcode[0],fragP->fr_address);
  2768.     fragP->fr_opcode[1]&= ~0x3F;
  2769.     fragP->fr_opcode[1]|=0x39;    /* Mode 7.1 */
  2770.     fragP->fr_fix+=4;
  2771.     /* md_number_to_chars(buffer_address,
  2772.                (long)(fragP->fr_symbol->sy_value + fragP->fr_offset),
  2773.                4); */
  2774.     ext=0;
  2775.   }
  2776.   if(ext) {
  2777.     md_number_to_chars(buffer_address,(long)disp,(int)ext);
  2778.     fragP->fr_fix+=ext;
  2779.   }
  2780. }
  2781.  
  2782. /* Force truly undefined symbols to their maximum size, and generally set up
  2783.    the frag list to be relaxed
  2784.  */
  2785. int
  2786. md_estimate_size_before_relax(fragP,segtype)
  2787. register fragS *fragP;
  2788. int segtype;
  2789. {
  2790.     int    old_fix;
  2791.  
  2792.     old_fix=fragP->fr_fix;
  2793.  
  2794.         /* handle SZ_UNDEF first, it can be changed to BYTE or SHORT */
  2795.     switch(fragP->fr_subtype) {
  2796.         case TAB(DBCC,SZ_UNDEF):
  2797.                 if((fragP->fr_symbol->sy_type&N_TYPE)==segtype) {
  2798.                         fragP->fr_subtype=TAB(DBCC,SHORT);
  2799.                         fragP->fr_var+=2;
  2800.                         break;
  2801.                 }
  2802.             /* only DBcc 68000 instructions can come here */
  2803.                 /* change dbcc into dbcc/jmp absl long */
  2804.                 fragP->fr_opcode[2] = 0x00;  /* branch offset = 4 */
  2805.                 fragP->fr_opcode[3] = 0x04;  
  2806.                 fragP->fr_opcode[4] = 0x60;  /* put in bra pc+6 */ 
  2807.                 fragP->fr_opcode[5] = 0x06;  
  2808.                 fragP->fr_opcode[6] = 0x4e;  /* put in jmp long (0x4ef9) */ 
  2809.                 fragP->fr_opcode[7] = 0xf9;  
  2810.                 fragP->fr_fix += 6;      /* account for bra/jmp instruction */
  2811.                 subseg_change(SEG_TEXT,0);
  2812.                 fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0, 
  2813.                              fragP->fr_offset,0);
  2814.                 fragP->fr_fix += 4;
  2815.                 frag_wane(fragP);
  2816.                 break;
  2817.                 
  2818.         case TAB(BCC68000,SZ_UNDEF):
  2819.                 if((fragP->fr_symbol->sy_type&N_TYPE)==segtype) {
  2820.                         fragP->fr_subtype=TAB(BCC68000,BYTE);
  2821.                         break;
  2822.                 }
  2823.             /* only Bcc 68000 instructions can come here */
  2824.                 /* change bcc into b!cc/jmp absl long */
  2825.             fragP->fr_opcode[0] ^= 0x01; /* invert bcc */
  2826.                 fragP->fr_opcode[1] = 0x6;   /* branch offset = 6 */
  2827.                 fragP->fr_opcode[2] = 0x4e;  /* put in jmp long (0x4ef9) */ 
  2828.                 fragP->fr_opcode[3] = 0xf9;  
  2829.                 fragP->fr_fix += 2;         /* account for jmp instruction */
  2830.                 subseg_change(SEG_TEXT,0);
  2831.                 fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0, 
  2832.                              fragP->fr_offset,0);
  2833.                 fragP->fr_fix += 4;
  2834.                 frag_wane(fragP);
  2835.                 break;
  2836.                 
  2837.     case TAB(BRANCH,SZ_UNDEF):
  2838.         if((fragP->fr_symbol->sy_type&N_TYPE)==segtype) {
  2839.                         fragP->fr_subtype=TAB(TABTYPE(fragP->fr_subtype),BYTE);
  2840.                         break;
  2841.         } else if(flagseen['m']) {
  2842.           if(fragP->fr_opcode[0]==0x61) {
  2843.             fragP->fr_opcode[0]= 0x4E;
  2844.             fragP->fr_opcode[1]= 0xB9;    /* JBSR with ABSL LONG offset */
  2845.             subseg_change(SEG_TEXT, 0);
  2846.                     fix_new(fragP, fragP->fr_fix, 4, 
  2847.                 fragP->fr_symbol, 0, fragP->fr_offset, 0);
  2848.             fragP->fr_fix+=4;
  2849.             frag_wane(fragP);
  2850.                   } else if(fragP->fr_opcode[0]==0x60) {
  2851.                     fragP->fr_opcode[0]= 0x4E;
  2852.                     fragP->fr_opcode[1]= 0xF9;  /* JMP  with ABSL LONG offset */
  2853.                     subseg_change(SEG_TEXT, 0);
  2854.                     fix_new(fragP, fragP->fr_fix, 4, 
  2855.                 fragP->fr_symbol, 0, fragP->fr_offset, 0);
  2856.                     fragP->fr_fix+=4;
  2857.                     frag_wane(fragP);
  2858.           } else {
  2859.                     as_warn("Long branch offset to extern symbol not supported.");
  2860.           }
  2861.         } else {    /* Symbol is still undefined.  Make it simple */
  2862.             fix_new(fragP,(int)(fragP->fr_fix),4,fragP->fr_symbol,
  2863.  (symbolS *)0,fragP->fr_offset+4,1);
  2864.             fragP->fr_fix+=4;
  2865.             fragP->fr_opcode[1]=0xff;
  2866.             frag_wane(fragP);
  2867.             break;
  2868.         }
  2869.     default:
  2870.                 break;
  2871.         }
  2872.  
  2873.         /* now that SZ_UNDEF are taken care of, check others */
  2874.         switch(fragP->fr_subtype) {
  2875.         case TAB(BCC68000,BYTE):
  2876.     case TAB(BRANCH,BYTE):
  2877.             /* We can't do a short jump to the next instruction,
  2878.                so we force word mode.  */
  2879.         if(fragP->fr_symbol && fragP->fr_symbol->sy_value==0 &&
  2880.  fragP->fr_symbol->sy_frag==fragP->fr_next) {
  2881.                         fragP->fr_subtype=TAB(TABTYPE(fragP->fr_subtype),SHORT);
  2882.             fragP->fr_var+=2;
  2883.         }
  2884.         break;
  2885.     case TAB(FBRANCH,SZ_UNDEF):
  2886.         if((fragP->fr_symbol->sy_type&N_TYPE)==segtype) {
  2887.             fragP->fr_subtype=TAB(FBRANCH,SHORT);
  2888.             fragP->fr_var+=2;
  2889.         } else {
  2890.             fragP->fr_subtype=TAB(FBRANCH,LONG);
  2891.             fragP->fr_var+=4;
  2892.         }
  2893.         break;
  2894.     case TAB(PCREL,SZ_UNDEF):
  2895.         if((fragP->fr_symbol->sy_type&N_TYPE)==segtype) {
  2896.             fragP->fr_subtype=TAB(PCREL,SHORT);
  2897.             fragP->fr_var+=2;
  2898.         } else {
  2899.             fragP->fr_subtype=TAB(PCREL,LONG);
  2900.             fragP->fr_var+=4;
  2901.         }
  2902.         break;
  2903.     default:
  2904.         break;
  2905.     }
  2906.     return fragP->fr_var + fragP->fr_fix - old_fix;
  2907. }
  2908.  
  2909. /* the bit-field entries in the relocation_info struct plays hell 
  2910.    with the byte-order problems of cross-assembly.  So as a hack,
  2911.    I added this mach. dependent ri twiddler.  Ugly, but it gets
  2912.    you there. -KWK */
  2913. /* on m68k: first 4 bytes are normal unsigned long, next three bytes
  2914. are symbolnum, most sig. byte first.  Last byte is broken up with
  2915. bit 7 as pcrel, bits 6 & 5 as length, bit 4 as pcrel, and the lower
  2916. nibble as nuthin. (on Sun 3 at least) */
  2917. void
  2918. md_ri_to_chars(ri_p, ri)
  2919.      struct relocation_info *ri_p, ri;
  2920. {
  2921.   unsigned char the_bytes[8];
  2922.   
  2923.   /* this is easy */
  2924.   md_number_to_chars(the_bytes, ri.r_address, sizeof(ri.r_address));
  2925.   /* now the fun stuff */
  2926.   the_bytes[4] = (ri.r_symbolnum >> 16) & 0x0ff;
  2927.   the_bytes[5] = (ri.r_symbolnum >> 8) & 0x0ff;
  2928.   the_bytes[6] = ri.r_symbolnum & 0x0ff;
  2929.   the_bytes[7] = (((ri.r_pcrel << 7)  & 0x80) | ((ri.r_length << 5) & 0x60) | 
  2930.     ((ri.r_extern << 4)  & 0x10)); 
  2931.   /* now put it back where you found it */
  2932.   bcopy (the_bytes, (char *)ri_p, sizeof(struct relocation_info));
  2933. }
  2934.  
  2935. #ifndef WORKING_DOT_WORD
  2936. int md_short_jump_size = 4;
  2937. int md_long_jump_size = 6;
  2938.  
  2939. void
  2940. md_create_short_jump(ptr,from_addr,to_addr,frag,to_symbol)
  2941. char    *ptr;
  2942. long    from_addr,
  2943.     to_addr;
  2944. fragS    *frag;
  2945. symbolS    *to_symbol;
  2946. {
  2947.     long offset;
  2948.  
  2949.     offset = to_addr - (from_addr+2);
  2950.  
  2951.     md_number_to_chars(ptr  ,(long)0x6000,2);
  2952.     md_number_to_chars(ptr+2,(long)offset,2);
  2953. }
  2954.  
  2955. void
  2956. md_create_long_jump(ptr,from_addr,to_addr,frag,to_symbol)
  2957. char    *ptr;
  2958. long    from_addr,
  2959.     to_addr;
  2960. fragS    *frag;
  2961. symbolS    *to_symbol;
  2962. {
  2963.     long offset;
  2964.  
  2965.     if(flagseen['m']) {
  2966.         offset=to_addr-to_symbol->sy_value;
  2967.         md_number_to_chars(ptr  ,(long)0x4EF9,2);
  2968.         md_number_to_chars(ptr+2,(long)offset,4);
  2969.         fix_new(frag,(ptr+2)-frag->fr_literal,4,to_symbol,(symbolS *)0,(long int)0,0);
  2970.     } else {
  2971.         offset=to_addr - (from_addr+2);
  2972.         md_number_to_chars(ptr  ,(long)0x60ff,2);
  2973.         md_number_to_chars(ptr+2,(long)offset,4);
  2974.     }
  2975. }
  2976.  
  2977. #endif
  2978. /* Different values of OK tell what its OK to return.  Things that aren't OK are an error (what a shock, no?)
  2979.  
  2980.     0:  Everything is OK
  2981.     10:  Absolute 1:8    only
  2982.     20:  Absolute 0:7    only
  2983.     30:  absolute 0:15    only
  2984.     40:  Absolute 0:31    only
  2985.     50:  absolute 0:127    only
  2986.     55:  absolute -64:63    only
  2987.     60:  absolute -128:127    only
  2988.     70:  absolute 0:4095    only
  2989.     80:  No bignums
  2990.  
  2991. */
  2992. int
  2993. get_num(exp,ok)
  2994. struct m68k_exp *exp;
  2995. int ok;
  2996. {
  2997. #ifdef TEST2
  2998.     long    l = 0;
  2999.  
  3000.     if(!exp->e_beg)
  3001.         return 0;
  3002.     if(*exp->e_beg=='0') {
  3003.         if(exp->e_beg[1]=='x')
  3004.             sscanf(exp->e_beg+2,"%x",&l);
  3005.         else
  3006.             sscanf(exp->e_beg+1,"%O",&l);
  3007.         return l;
  3008.     }
  3009.     return atol(exp->e_beg);
  3010. #else
  3011.     char    *save_in;
  3012.     char    c_save;
  3013.  
  3014.     if(!exp) {
  3015.         /* Can't do anything */
  3016.         return 0;
  3017.     }
  3018.     if(!exp->e_beg || !exp->e_end) {
  3019.         seg(exp)=SEG_ABSOLUTE;
  3020.         adds(exp)=0;
  3021.         subs(exp)=0;
  3022.         offs(exp)= (ok==10) ? 1 : 0;
  3023.         as_warn("Null expression defaults to %ld",offs(exp));
  3024.         return 0;
  3025.     }
  3026.  
  3027.     exp->e_siz=0;
  3028.     if(/* ok!=80 && */exp->e_end[-1]==':' && (exp->e_end-exp->e_beg)>2) {
  3029.         switch(exp->e_end[0]) {
  3030.         case 's':
  3031.         case 'b':
  3032.             exp->e_siz=1;
  3033.             break;
  3034.         case 'w':
  3035.             exp->e_siz=2;
  3036.             break;
  3037.         case 'l':
  3038.             exp->e_siz=3;
  3039.             break;
  3040.         default:
  3041.             as_warn("Unknown size for expression \"%c\"",exp->e_end[0]);
  3042.         }
  3043.         exp->e_end-=2;
  3044.     }
  3045.     c_save=exp->e_end[1];
  3046.     exp->e_end[1]='\0';
  3047.     save_in=input_line_pointer;
  3048.     input_line_pointer=exp->e_beg;
  3049.     switch(expression(&(exp->e_exp))) {
  3050.     case SEG_NONE:
  3051.         /* Do the same thing the VAX asm does */
  3052.         seg(exp)=SEG_ABSOLUTE;
  3053.         adds(exp)=0;
  3054.         subs(exp)=0;
  3055.         offs(exp)=0;
  3056.         if(ok==10) {
  3057.             as_warn("expression out of range: defaulting to 1");
  3058.             offs(exp)=1;
  3059.         }
  3060.         break;
  3061.     case SEG_ABSOLUTE:
  3062.         switch(ok) {
  3063.         case 10:
  3064.             if(offs(exp)<1 || offs(exp)>8) {
  3065.                 as_warn("expression out of range: defaulting to 1");
  3066.                 offs(exp)=1;
  3067.             }
  3068.             break;
  3069.         case 20:
  3070.             if(offs(exp)<0 || offs(exp)>7)
  3071.                 goto outrange;
  3072.             break;
  3073.         case 30:
  3074.             if(offs(exp)<0 || offs(exp)>15)
  3075.                 goto outrange;
  3076.             break;
  3077.         case 40:
  3078.             if(offs(exp)<0 || offs(exp)>32)
  3079.                 goto outrange;
  3080.             break;
  3081.         case 50:
  3082.             if(offs(exp)<0 || offs(exp)>127)
  3083.                 goto outrange;
  3084.             break;
  3085.         case 55:
  3086.             if(offs(exp)<-64 || offs(exp)>63)
  3087.                 goto outrange;
  3088.             break;
  3089.         case 60:
  3090.             if(offs(exp)<-128 || offs(exp)>127)
  3091.                 goto outrange;
  3092.             break;
  3093.         case 70:
  3094.             if(offs(exp)<0 || offs(exp)>4095) {
  3095.             outrange:
  3096.                 as_warn("expression out of range: defaulting to 0");
  3097.                 offs(exp)=0;
  3098.             }
  3099.             break;
  3100.         default:
  3101.             break;
  3102.         }
  3103.         break;
  3104.     case SEG_TEXT:
  3105.     case SEG_DATA:
  3106.     case SEG_BSS:
  3107.     case SEG_UNKNOWN:
  3108.     case SEG_DIFFERENCE:
  3109.         if(ok>=10 && ok<=70) {
  3110.             seg(exp)=SEG_ABSOLUTE;
  3111.             adds(exp)=0;
  3112.             subs(exp)=0;
  3113.             offs(exp)= (ok==10) ? 1 : 0;
  3114.             as_warn("Can't deal with expression \"%s\": defaulting to %ld",exp->e_beg,offs(exp));
  3115.         }
  3116.         break;
  3117.     case SEG_BIG:
  3118.         if(ok==80 && offs(exp)<0) {    /* HACK! Turn it into a long */
  3119.             LITTLENUM_TYPE words[6];
  3120.  
  3121.             gen_to_words(words,2,8L);/* These numbers are magic! */
  3122.             seg(exp)=SEG_ABSOLUTE;
  3123.             adds(exp)=0;
  3124.             subs(exp)=0;
  3125.             offs(exp)=words[1]|(words[0]<<16);
  3126.         } else if(ok!=0) {
  3127.             seg(exp)=SEG_ABSOLUTE;
  3128.             adds(exp)=0;
  3129.             subs(exp)=0;
  3130.             offs(exp)= (ok==10) ? 1 : 0;
  3131.             as_warn("Can't deal with expression \"%s\": defaulting to %ld",exp->e_beg,offs(exp));
  3132.         }
  3133.         break;
  3134.     default:
  3135.         abort();
  3136.     }
  3137.     if(input_line_pointer!=exp->e_end+1)
  3138.         as_warn("Ignoring junk after expression");
  3139.     exp->e_end[1]=c_save;
  3140.     input_line_pointer=save_in;
  3141.     if(exp->e_siz) {
  3142.         switch(exp->e_siz) {
  3143.         case 1:
  3144.             if(!isbyte(offs(exp)))
  3145.                 as_warn("expression doesn't fit in BYTE");
  3146.             break;
  3147.         case 2:
  3148.             if(!isword(offs(exp)))
  3149.                 as_warn("expression doesn't fit in WORD");
  3150.             break;
  3151.         }
  3152.     }
  3153.     return offs(exp);
  3154. #endif
  3155. }
  3156.  
  3157. /* These are the back-ends for the various machine dependent pseudo-ops.  */
  3158. void demand_empty_rest_of_line();    /* Hate those extra verbose names */
  3159.  
  3160. void
  3161. s_data1()
  3162. {
  3163.     subseg_new(SEG_DATA,1);
  3164.     demand_empty_rest_of_line();
  3165. }
  3166.  
  3167. void
  3168. s_data2()
  3169. {
  3170.     subseg_new(SEG_DATA,2);
  3171.     demand_empty_rest_of_line();
  3172. }
  3173.  
  3174. void
  3175. s_even()
  3176. {
  3177.     register int temp;
  3178.     register long int temp_fill;
  3179.  
  3180.     temp = 1;        /* JF should be 2? */
  3181.     temp_fill = get_absolute_expression ();
  3182.     if ( ! need_pass_2 ) /* Never make frag if expect extra pass. */
  3183.         frag_align (temp, (int)temp_fill);
  3184.     demand_empty_rest_of_line();
  3185. }
  3186.  
  3187. /* s_space is defined in read.c .skip is simply an alias to it. */
  3188.  
  3189. int
  3190. md_parse_option(argP,cntP,vecP)
  3191. char **argP;
  3192. int *cntP;
  3193. char ***vecP;
  3194. {
  3195.     switch(**argP) {
  3196.     case 'l':    /* -l means keep external to 2 bit offset
  3197.                rather than 16 bit one */
  3198.         break;
  3199.  
  3200.     case 'm':
  3201.         /* Gas simply ignores this option! */
  3202.         (*argP)++;
  3203.         if(**argP=='c')
  3204.             (*argP)++;
  3205.         if(!strcmp(*argP,"68000"))
  3206.             flagseen['m']=2;
  3207.         else if(!strcmp(*argP,"68010")) {
  3208. #ifdef M_SUN
  3209.             omagic= 1<<16|OMAGIC;
  3210. #endif
  3211.             flagseen['m']=1;
  3212.         } else if(!strcmp(*argP,"68020"))
  3213.             flagseen['m']=0;
  3214.         else
  3215.             as_warn("Unknown -m option ignored");
  3216.         while(**argP)
  3217.             (*argP)++;
  3218.         break;
  3219.  
  3220.     default:
  3221.         return 0;
  3222.     }
  3223.     return 1;
  3224. }
  3225.  
  3226.  
  3227. #ifdef TEST2
  3228.  
  3229. /* TEST2:  Test md_assemble() */
  3230. /* Warning, this routine probably doesn't work anymore */
  3231.  
  3232. main()
  3233. {
  3234.     struct m68_it the_ins;
  3235.     char buf[120];
  3236.     char *cp;
  3237.     int    n;
  3238.  
  3239.     m68_ip_begin();
  3240.     for(;;) {
  3241.         if(!gets(buf) || !*buf)
  3242.             break;
  3243.         if(buf[0]=='|' || buf[1]=='.')
  3244.             continue;
  3245.         for(cp=buf;*cp;cp++)
  3246.             if(*cp=='\t')
  3247.                 *cp=' ';
  3248.         if(is_label(buf))
  3249.             continue;
  3250.         bzero(&the_ins,sizeof(the_ins));
  3251.         m68_ip(&the_ins,buf);
  3252.         if(the_ins.error) {
  3253.             printf("Error %s in %s\n",the_ins.error,buf);
  3254.         } else {
  3255.             printf("Opcode(%d.%s): ",the_ins.numo,the_ins.args);
  3256.             for(n=0;n<the_ins.numo;n++)
  3257.                 printf(" 0x%x",the_ins.opcode[n]&0xffff);
  3258.             printf("    ");
  3259.             print_the_insn(&the_ins.opcode[0],stdout);
  3260.             (void)putchar('\n');
  3261.         }
  3262.         for(n=0;n<strlen(the_ins.args)/2;n++) {
  3263.             if(the_ins.operands[n].error) {
  3264.                 printf("op%d Error %s in %s\n",n,the_ins.operands[n].error,buf);
  3265.                 continue;
  3266.             }
  3267.             printf("mode %d, reg %d, ",the_ins.operands[n].mode,the_ins.operands[n].reg);
  3268.             if(the_ins.operands[n].b_const)
  3269.                 printf("Constant: '%.*s', ",1+the_ins.operands[n].e_const-the_ins.operands[n].b_const,the_ins.operands[n].b_const);
  3270.             printf("ireg %d, isiz %d, imul %d, ",the_ins.operands[n].ireg,the_ins.operands[n].isiz,the_ins.operands[n].imul);
  3271.             if(the_ins.operands[n].b_iadd)
  3272.                 printf("Iadd: '%.*s',",1+the_ins.operands[n].e_iadd-the_ins.operands[n].b_iadd,the_ins.operands[n].b_iadd);
  3273.             (void)putchar('\n');
  3274.         }
  3275.     }
  3276.     m68_ip_end();
  3277.     return 0;
  3278. }
  3279.  
  3280. is_label(str)
  3281. char *str;
  3282. {
  3283.     while(*str==' ')
  3284.         str++;
  3285.     while(*str && *str!=' ')
  3286.         str++;
  3287.     if(str[-1]==':' || str[1]=='=')
  3288.         return 1;
  3289.     return 0;
  3290. }
  3291.  
  3292. print_address(add,fp)
  3293. FILE *fp;
  3294. {
  3295.     fprintf(fp,"%#X",add);
  3296. }
  3297.  
  3298. #endif
  3299.  
  3300. /* Possible states for relaxation:
  3301.  
  3302. 0 0    branch offset    byte    (bra, etc)
  3303. 0 1            word
  3304. 0 2            long
  3305.  
  3306. 1 0    indexed offsets    byte    a0@(32,d4:w:1) etc
  3307. 1 1            word
  3308. 1 2            long
  3309.  
  3310. 2 0    two-offset index word-word a0@(32,d4)@(45) etc
  3311. 2 1            word-long
  3312. 2 2            long-word
  3313. 2 3            long-long
  3314.  
  3315. */
  3316.  
  3317.  
  3318.  
  3319. #ifdef DONTDEF
  3320. abort()
  3321. {
  3322.     printf("ABORT!\n");
  3323.     exit(12);
  3324. }
  3325.  
  3326. char *index(s,c)
  3327. char *s;
  3328. {
  3329.     while(*s!=c) {
  3330.         if(!*s) return 0;
  3331.         s++;
  3332.     }
  3333.     return s;
  3334. }
  3335.  
  3336. bzero(s,n)
  3337. char *s;
  3338. {
  3339.     while(n--)
  3340.         *s++=0;
  3341. }
  3342.  
  3343. print_frags()
  3344. {
  3345.     fragS *fragP;
  3346.     extern fragS *text_frag_root;
  3347.  
  3348.     for(fragP=text_frag_root;fragP;fragP=fragP->fr_next) {
  3349.         printf("addr %lu  next 0x%x  fix %ld  var %ld  symbol 0x%x  offset %ld\n",
  3350.  fragP->fr_address,fragP->fr_next,fragP->fr_fix,fragP->fr_var,fragP->fr_symbol,fragP->fr_offset);
  3351.         printf("opcode 0x%x  type %d  subtype %d\n\n",fragP->fr_opcode,fragP->fr_type,fragP->fr_subtype);
  3352.     }
  3353.     fflush(stdout);
  3354.     return 0;
  3355. }
  3356. #endif
  3357.  
  3358. #ifdef DONTDEF
  3359. /*VARARGS1*/
  3360. panic(format,args)
  3361. char *format;
  3362. {
  3363.     fputs("Internal error:",stderr);
  3364.     _doprnt(format,&args,stderr);
  3365.     (void)putc('\n',stderr);
  3366.     as_where();
  3367.     abort();
  3368. }
  3369. #endif
  3370.